How to use the props function from bluebird
Find comprehensive JavaScript bluebird.props code examples handpicked from public code repositorys.
bluebird.props is a function in the Bluebird library that converts an object containing promises into a promise that resolves to an object containing the resolved values of those promises.
GitHub: TryGhost/express-hbs
![TryGhost profile picture](/TryGhost.png?size=40)
20 21 22 23 24 25 26 27 28 29
}); return id; } function done(cache, callback) { Promise.props(cache).then(function(values) { callback(null, values); }).catch(function(error) { callback(error); });
+ 5 other calls in file
53 54 55 56 57 58 59 60 61 62
cssnano({ preset: { plugins: [normalizeWhitespace, discardComments] } }) ]).process(String(expectedBuffer)); return Promise.props({ actualResult: actualResult, expectedResult: expectedResult }); })
How does bluebird.props work?
bluebird.props
works by taking an object containing promises as input and returning a new promise that resolves to an object containing the resolved values of those promises.
The function iterates over the input object and waits for all the promises to settle. Once all the promises have settled, bluebird.props
resolves the new promise with an object that has the same keys as the input object, but with their values replaced by the resolved values of the corresponding promises.
If any of the input promises are rejected, the new promise returned by bluebird.props
is immediately rejected with the reason of the first rejected promise.
bluebird.props
can be useful when working with a set of promises that need to be resolved before further processing can take place, such as when waiting for data from multiple asynchronous sources.
By using bluebird.props
, we can efficiently wait for all the promises to settle and retrieve their resolved values in a single object, rather than individually awaiting each promise and collecting its resolved value.
65 66 67 68 69 70 71 72 73 74
exports.allAsync = function (myRequests) { if (_.isArray(myRequests)) { return Promise.all(wrapToArray(myRequests)); } else if (_.isObject(myRequests)) { return Promise.props(wrapToObject(myRequests)); } }; // Aux Functions
624 625 626 627 628 629 630 631 632 633
p1: resolved('p1'), p2: resolved('p2'), p3: resolved('p3') } Promise.props(props).then(function (result) { t.deepEqual(result, { p1: 'p1', p2: 'p2', p3: 'p3' }) t.strictEqual(ins.currTransaction().id, trans.id) }) })
+ 2 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13
const Promise = require("bluebird"); const promises = { name: Promise.resolve("Alice"), age: Promise.resolve(25), address: Promise.resolve("123 Main St."), }; const promiseOfProps = Promise.props(promises); promiseOfProps.then((result) => { console.log(result); });
In this example, we use bluebird.props to convert an object containing promises into a promise that resolves to an object containing the resolved values of those promises. We define an object promises that contains three promises, each resolving to a different value. We then pass the promises object to Promise.props to create a new promise that resolves to an object containing the resolved values of the input promises. We attach a then callback to the new promise that logs the resulting object to the console. By using bluebird.props in this way, we can efficiently wait for all the input promises to settle and retrieve their resolved values in a single object.
194 195 196 197 198 199 200 201 202 203
}) .then((userId) => Promise.all([ userId, this.propositionsDao.countEquivalentPropositions(proposition), Promise.props({ [userActionsConflictCodes.OTHER_USERS_HAVE_ROOTED_JUSTIFICATIONS_IN_THIS_PROPOSITION]: this.propositionsDao.hasOtherUsersRootedJustifications( proposition, userId
+ 29 other calls in file
189 190 191 192 193 194 195 196 197 198
* @param {string} kind see {File#load} * @param {BlobStore} blobStore * @return {Promise} */ loadFiles(kind, blobStore) { return BPromise.props(this.fileMap.map(file => file.load(kind, blobStore))) } /** * Store each of the files in this snapshot and return the raw snapshot for
+ 5 other calls in file
GitHub: DenzelHopkins/ghost
279 280 281 282 283 284 285 286 287 288
self.set('password', hash); }); })(); } return Promise.props(tasks); }, toJSON: function toJSON(unfilteredOptions) { const options = User.filterOptions(unfilteredOptions, 'toJSON');
+ 4 other calls in file
bluebird.reject is the most popular function in bluebird (2988 examples)