import * as events from 'events' ; import { inject , injectable } from 'inversify' ; import ILogger from '../ILogger' ; import ILoggerModel from '../ILoggerModel' ; import IReserveEvent , { IReserveUpdateValues } from './IReserveEvent' ; @ injectable ( ) class ReserveEvent implements IReserveEvent { private log : ILogger ; private emitter : events . EventEmitter = new events . EventEmitter ( ) ; constructor ( @ inject ( 'ILoggerModel' ) logger ) { this . log = logger . getLogger ( ) ; } param diff public emitUpdated ( diff ) { this . emitter . emit ( ReserveEvent . UPDATE_EVENT , diff ) ; } param callback public setUpdated ( callback ) { this . emitter . on ( ReserveEvent . UPDATE_EVENT , async ( diff ) => { try { await callback ( diff ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } } namespace ReserveEvent { export const UPDATE_EVENT = 'ReserveUpdateEvent' ; } export default ReserveEvent ;