PromiseData
Executes a list of promises and stores the the results in a data object
Installation
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js.
Installation is done using the
npm install
command:
$ npm install promise-data
Usage
Import
import PromiseData from 'promise-data';
Runs Promises Synchronously
PromiseData.sync([
{prop: 'prop0', promise: () => myPromise('param')},
{prop: 'prop1', promise: mySecondPromise}
]).then(function(data) {
console.log(data.prop0); // the result from myPromise('param')
console.log(data.prop1); // the result from mySecondPromise()
});
Runs Promises Asynchronously
PromiseData.async([
{prop: 'prop0', promise: () => myPromise('param');},
{prop: 'prop1', promise: mySecondPromise}
]).then(function(data) {
console.log(data.prop0); // the result from myPromise('param')
console.log(data.prop1); // the result from mySecondPromise()
});
Simplified Data Format
PromiseData.async({
prop0: () => myPromise('param'),
prop1: mySecondPromise
}).then(function(data) {
console.log(data.prop0); // the result from myPromise('param')
console.log(data.prop1); // the result from mySecondPromise()
});
Credits
License
Copyright (c) 2018 Thomas Boles [https://github.com/tcboles]