2018-09-02 16:09:49 +00:00
|
|
|
import * as plugins from './smartevent.plugins';
|
2023-07-10 00:48:58 +00:00
|
|
|
|
2018-09-02 16:09:49 +00:00
|
|
|
import { EventEmitter } from 'events';
|
2017-04-29 19:23:26 +00:00
|
|
|
|
2023-07-10 00:48:58 +00:00
|
|
|
export {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
export class SmartEventEmitter {
|
|
|
|
public eventSubject = new plugins.
|
|
|
|
|
|
|
|
public once () {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
public emit () {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public on () {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// instrument globalThis
|
2017-04-29 19:23:26 +00:00
|
|
|
|
2023-07-10 00:48:58 +00:00
|
|
|
export const once = async <T>(eventEmitter: SmartEventEmitter, eventName: string): Promise<T> => {
|
2018-12-10 22:41:41 +00:00
|
|
|
const done = plugins.smartpromise.defer<T>();
|
|
|
|
eventEmitter.once(eventName, eventPayload => {
|
|
|
|
done.resolve(eventPayload);
|
|
|
|
});
|
2018-09-02 16:09:49 +00:00
|
|
|
return await done.promise;
|
|
|
|
};
|