back to Overview

promise.fire()

Changes the state of the promise into either fulfilled or rejected.
Complete distribution only, not available in stand-alone modules.

Syntax Variants

_.fire(newState)
_.fire(newState, values)

Parameters

newState
true to set the Promise to fulfilled, false to set the state as rejected. If you pass null or undefined, the promise's state does not change.
values (optional)
an array of values to pass to then() handlers as arguments. You can also pass a non-list argument, which will then be passed as only argument.
(return value)
the promise

Description

Changes the state of the promise into either fulfilled or rejected. This will also notify all then() handlers. If the promise already has a state, the call will be ignored.

fire() can be invoked as a function without context ('this'). Every promise has its own instance.

Example

A simple promise that is fulfilled after 1 second, using Minified's invocation syntax:

var p = _.promise();
setTimeout(function() {
    p.fire(true, []);
}, 1000);

Example

Call fire() without a context:

var p = _.promise(function(resolve, reject) {
    setTimeout(resolve.fire, 1000);
});

Comments

comments powered by Disqus

back to Overview

Functions