type Listener < T = any > = ( data ? : T ) => unknown ; export default abstract class RinzlerEventEmitter { #listeners : Map < string , Listener [ ] > = new Map ( ) ; #onceListeners : Map < string , Listener [ ] > = new Map ( ) ; on < T > ( event , func ) { this . #listeners . get ( event ) ?. push ( func ) || this . #listeners . set ( event , [ func ] ) ; } once < T > ( event , func ) { this . #onceListeners . get ( event ) ?. push ( func ) || this . #onceListeners . set ( event , [ func ] ) ; } waitFor < T = undefined > ( event ) { return new Promise ( resolve => { this . once < T > ( event , ( e ) => { resolve ( e as T ) ; } ) ; } ) ; } protected async _triggerEvent < T > ( event , data ? ) { this . #listeners . get ( event ) ?. forEach ( listener => { listener ( data ) ; } ) ; if ( this . #onceListeners . has ( event ) ) { const listeners = this . #onceListeners . get ( event ) ; this . #onceListeners . set ( event , [ ] ) ; listeners ?. map ( listener => { listener ( data ) ; } ) ; } } }