Deferred collects callbacks for process, resolve and reject. When any of these methods is called on an instance of an Deferred, all registered function are called.
All applicable callback functions are called in the order of their registration.
Callback functions can be registered after a Deferred has been resolved or rejected. They will be called back immediately using the same arguments as were used when the Defeered was resolved or rejected.
Register a callback function func to be called when resolve is called on the Deferred.
Register a callback function func to be called when fail is called on the Deferred.
Register a callback function func to be called when notify is called on the Deferred.
Register a callback Function func to be called when resolve or fail is called on the Deferred.
Resolves the Deferred, all registered done and always callbacks are called. The state is set to resolved. All arguments passed to this method are passed on to the callback functions.
Rejects the Deferred, all registered done and always callbacks are called. The state is set to rejected.
Notify all registered process callbacks. The state is unchanged.
Returns a CUI.Promise. This is like a Deferred, but with limited abilities.
Returns the state of the Deferred:
- pending This is the initial state when the Deferred is created.
- resolved State after the Deferred has been resolved by calling the resolve method.
- rejected State after the Deferred has been rejected by calling the reject method.
Each Deferred gets assigned a unique id. This can be useful for debugging purposes.
Returns an already resolved Deferred, using the given arguments.
Returns an already rejected Deferred, using the given arguments.
The Promise is a proxy for the methods done, fail, always, state, and getUniqueId of the passed CUI.Deferred. A Promise is not to be designed to be created directly but to be retrieved by calling promise on an existing CUI.Deferred.
Returns a Promise which calls done, fail, or process when any of the passed CUI.Deferred receive a resolve, reject, or notify call. The arguments can be instances of CUI.Deferred, CUI.Promise or Array of such instances. The Promise waits before all underlying CUI.Deferred or CUI.Promise are resolved, but fails immediately when the first CUI.Deferred or CUI.Promise is rejected. In the case of resolve, the done callback of the CUI.Promise returned by CUI.when, receives an Array of all arguments passed to the indivual underlying CUI.Deferred or CUI.Promise.
Returns a CUI.Promise which resolves if the passed decide is a CUI.Promise and is being resolved (passing on all the arguments).
If the passed CUI.Promise is rejcted the returned CUI.Promise is also rejected (passing on all the arguments).
If the passed decide is Boolean false the CUI.Promise is rejected with decide as argument.
If the passed decide is not false and not a CUI.Promise the returned CUI.Promise is resolved with decide as argument.