import IMessage from '../IMessage' ; import IMessageManager from './IMessageManager' ; import IMessageHandler from '../Handler/IMessageHandler' ; import HandleResult from '../Handler/HandleResult' ; import IEventDispatcher from '../../Event/IEventDispatcher' ; class MessageManager implements IMessageManager { constructor ( private eventDispatcher , private handlers = [ ] ) { } public HandlerRegister < T extends IMessageHandler > ( handler ) { this . handlers . push ( new handler ( ) ) ; } public async ProcessMessage ( message ) { let handled = false ; for ( const handler of this . handlers ) { const result = await handler . Handle ( message ) ; if ( result === HandleResult . Handled ) { handled = true ; break ; } } } } export default MessageManager ;