smartevent/ts/index.ts
2018-12-10 23:41:41 +01:00

13 lines
376 B
TypeScript

import * as plugins from './smartevent.plugins';
import { EventEmitter } from 'events';
export { EventEmitter };
export const once = async <T>(eventEmitter: EventEmitter, eventName: string): Promise<T> => {
const done = plugins.smartpromise.defer<T>();
eventEmitter.once(eventName, eventPayload => {
done.resolve(eventPayload);
});
return await done.promise;
};