new signals.PromiseSignal()
The PromiseSignal constructor does not take any parameters.
- Source:
Example
Creating and Using a PromiseSignal
This example shows how to setup a PromiseSignal that has one listener which fulfills the promise immediately. The fulfillment listener is invoked because it was registered as first argument to the dispatch(…).then() method of the promise.var promiseSignal = new signals.PromiseSignal(), fulfillData = {}, dispatchData = {}; function signalListener(data, promise) { expect.equal(data, dispatchData, 'Expected to receive dispatched data') // here the listener fulfills the promise! promise.fulfill(fulfillData); } // when the listener fulfills the promise this function is called function promiseFulfilledListener(data) { expect.equal(data, fulfillData, 'Expected fulfill data'); } promiseSignal.add(signalListener); promiseSignal.dispatch(dispatchData).then(promiseFulfilledListener);
Methods
-
dispatch(any) → {Promise}
-
Dispatches the signal like the base class but returns a new promise object and provides all listeners with the promise fulfill and reject functions.
Parameters:
Name Type Description any
* data that should be dispatched to the listeners
- Source:
Returns:
A Promise A/+ instance
- Type
- Promise