Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/async-event-emitter.js

30 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const emittery_1 = __importDefault(require("emittery"));
class AsyncEventEmitter extends emittery_1.default {
constructor({ captureRejections = false } = {}) {
super();
this.captureRejections = captureRejections;
}
once(event, listener) {
if (!listener)
return super.once(event);
const unsubscribe = this.on(event, async (data) => {
unsubscribe();
return listener(data);
});
return Promise.resolve();
}
emit(eventName, ...args) {
const emitPromise = super.emit(eventName, ...args);
if (this.captureRejections && eventName !== 'error')
emitPromise.catch(reason => this.emit('error', reason));
return emitPromise;
}
}
exports.default = AsyncEventEmitter;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXN5bmMtZXZlbnQtZW1pdHRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9hc3luYy1ldmVudC1lbWl0dGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsd0RBQWdDO0FBRWhDLE1BQXFCLGlCQUFrQixTQUFRLGtCQUFRO0lBR25ELFlBQW9CLEVBQUUsaUJBQWlCLEdBQUcsS0FBSyxFQUFFLEdBQUcsRUFBRTtRQUNsRCxLQUFLLEVBQUUsQ0FBQztRQUVSLElBQUksQ0FBQyxpQkFBaUIsR0FBRyxpQkFBaUIsQ0FBQztJQUMvQyxDQUFDO0lBRU0sSUFBSSxDQUFFLEtBQWEsRUFBRSxRQUFtQjtRQUMzQyxJQUFJLENBQUMsUUFBUTtZQUNULE9BQU8sS0FBSyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsQ0FBQztRQUU3QixNQUFNLFdBQVcsR0FBRyxJQUFJLENBQUMsRUFBRSxDQUF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