ste-promise-signals
Version:
Add the power of Promise Signals to your projects. They are the most bare bones implementation of an event that supports promises.
45 lines (44 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromiseSignalDispatcher = void 0;
const ste_core_1 = require("ste-core");
/**
* The dispatcher handles the storage of subsciptions and facilitates
* subscription, unsubscription and dispatching of a signal event.
*/
class PromiseSignalDispatcher extends ste_core_1.PromiseDispatcherBase {
/**
* Creates a new SignalDispatcher instance.
*/
constructor() {
super();
}
/**
* Dispatches the signal.
*
* @returns {IPropagationStatus} The status of the dispatch.
*
* @memberOf SignalDispatcher
*/
async dispatch() {
const result = await this._dispatchAsPromise(false, this, arguments);
if (result == null) {
throw new ste_core_1.DispatchError("Got `null` back from dispatch.");
}
return result;
}
/**
* Dispatches the signal threaded.
*/
dispatchAsync() {
this._dispatchAsPromise(true, this, arguments);
}
/**
* Creates an event from the dispatcher. Will return the dispatcher
* in a wrapper. This will prevent exposure of any dispatcher methods.
*/
asEvent() {
return super.asEvent();
}
}
exports.PromiseSignalDispatcher = PromiseSignalDispatcher;