smartevent/ts/index.ts

13 lines
376 B
TypeScript
Raw Normal View History

import * as plugins from './smartevent.plugins';
import { EventEmitter } from 'events';
2017-04-29 19:23:26 +00:00
export { EventEmitter };
2017-04-29 19:23:26 +00:00
2018-12-10 22:41:41 +00:00
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;
};