Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 1x 1x 1x 2x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import EventEmitter from 'await-event-emitter'; /** * * @param {string} type - name of the event * @returns {symbol} - symbol */ export const EventType = (type) => Symbol(type); /** * EventManager for node-platform, you can extend it to create your own EventManager */ export class EventManager extends EventEmitter { constructor(events, Ename = 'node-platform') { super(); this.events = events; this.name = name; Object.freeze(this.name); // avoid changing EventManager name } /** * * @param {symbol} event - Symbol of the event to emit * @param {...any} args - list of arguments to pass to the event separated by comma * @returns {Promise<EventManager>} - Return a promise that the event will be completed */ async emit(event, ...args) { const evtName = event.toString().slice(7, -1); // remove "Symbol()" from description Iif (!this.events[evtName] || this.events[evtName] != event) { throw new Error( 'EventManager (' + this.name + ') have no event: ' + evtName, ); } await super.emit(event, ...args); return this; } /** @callback listenerCb @param {...Object} args */ /** * * @param {symbol} event - Symbol of the event to register on * @param {listenerCb} listener - Callback function that will be called when the emit will be emitted * @instance * @returns {EventManager} - Returns the EventManager instance to eventually continue with the chain */ on(event, listener) { const evtName = event.toString().slice(7, -1); // remove "Symbol()" from description Iif (!this.events[evtName] || this.events[evtName] != event) { throw new Error( 'EventManager (' + this.name + ') have no event: ' + evtName, ); } super.on(event, listener); return this; } } |