import * as events from 'events' ; import { inject , injectable } from 'inversify' ; import ILogger from '../ILogger' ; import ILoggerModel from '../ILoggerModel' ; import IEPGUpdateEvent from './IEPGUpdateEvent' ; @ injectable ( ) class EPGUpdateEvent implements IEPGUpdateEvent { private log : ILogger ; private emitter : events . EventEmitter = new events . EventEmitter ( ) ; constructor ( @ inject ( 'ILoggerModel' ) logger ) { this . log = logger . getLogger ( ) ; } /**
     * EPG 更新完了イベント発行
     */ public emitUpdated ( ) { this . emitter . emit ( EPGUpdateEvent . UPDATED_EVENT ) ; } param callback public setUpdated ( callback ) { this . emitter . on ( EPGUpdateEvent . UPDATED_EVENT , async ( ) => { try { await callback ( ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setUpdatedOnce ( callback ) { this . emitter . once ( EPGUpdateEvent . UPDATED_EVENT , async ( ) => { try { await callback ( ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } } namespace EPGUpdateEvent { export const UPDATED_EVENT = 'updated' ; } export default EPGUpdateEvent ;