UNPKG

676 BJavaScriptView Raw
1/* --------------------
2 * lock-queue module
3 * Deferred promise
4 * -------------------- */
5
6// Modules
7var Promise = require('bluebird');
8
9// Exports
10
11/**
12 * Deferred factory.
13 *
14 * `deferred.promise` is a promise in pending state which can be resolved or rejected
15 * by calling `deferred.resolve()` or `deferred.reject()`.
16 *
17 * @returns {Object} - Deferred object
18 * @returns {Promise} .promise
19 * @returns {Function} .resolve
20 * @returns {Function} .reject
21 */
22module.exports = function() {
23 var deferred = {};
24
25 deferred.promise = new Promise(function(resolve, reject) {
26 deferred.resolve = resolve;
27 deferred.reject = reject;
28 });
29
30 return deferred;
31};