@ply-ct/ply
Version:
REST API Automated Testing
39 lines • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypedEvent = void 0;
class TypedEvent {
constructor() {
this.listeners = [];
this.oncers = [];
}
on(listener) {
this.listeners.push(listener);
return {
dispose: () => this.off(listener)
};
}
once(listener) {
this.oncers.push(listener);
}
off(listener) {
const callbackIndex = this.listeners.indexOf(listener);
if (callbackIndex > -1) {
this.listeners.splice(callbackIndex, 1);
}
}
emit(event) {
// notify general listeners
this.listeners.forEach((listener) => listener(event));
// clear the oncers queue
if (this.oncers.length > 0) {
const toCall = this.oncers;
this.oncers = [];
toCall.forEach((listener) => listener(event));
}
}
pipe(te) {
return this.on((e) => te.emit(e));
}
}
exports.TypedEvent = TypedEvent;
//# sourceMappingURL=event.js.map