Function
defer (label) Object public
Module:
rsvp
Defined in node_modules/rsvp/lib/rsvp/defer.js:3
import { defer } from 'rsvp'; |
- label
- String
- optional string for labeling the promise. Useful for tooling.
- returns
- Object
defer
returns an object similar to jQuery's $.Deferred
.
defer
should be used when porting over code reliant on $.Deferred
's
interface. New code should use the Promise
constructor instead.
The object returned from defer
is a plain object with three properties:
- promise - an
Promise
. - reject - a function that causes the
promise
property on this object to become rejected - resolve - a function that causes the
promise
property on this object to become fulfilled.
Example:
1 2 3 4 5 6 7 |
let deferred = defer(); deferred.resolve("Success!"); deferred.promise.then(function(value){ // value here is "Success!" }); |