import { EventEmitter } from 'events' ; import { PROP_METADATA } from '../../libs/decorators' ; import { IpcActionServer } from '../../libs/ipc' ; export abstract class Service extends EventEmitter { protected ipc : IpcActionServer ; protected constructor ( public readonly name ) { super ( ) ; this . ipc = new IpcActionServer ( name ) ; this . ipc . setActionErrorHandler ( error => this . handleError ( error ) ) ; const actionHandlers = this . constructor [ PROP_METADATA ] ; if ( actionHandlers ) { for ( const actionName of Object . keys ( actionHandlers ) ) { const action = actionHandlers [ actionName ] [ 0 ] . actionName ; const method = this [ actionName ] ; this . ipc . setActionHandler ( action , method . bind ( this ) ) ; } } } abstract init ( ... di ) ; abstract handleError < E = any , T = any > ( error ) ; destroy ( ) { this . ipc . destroy ( ) ; } }