auto-promise is yet another version of the awesome async.auto, but for promises. In contrast to other implementations it can be used in two modes: Injected and classic. Also, it supports node-style callbacks intermixed.
npm install auto-promise
let auto = require('auto-promise');
auto(tasks).then(results => { ... });
Tasks can be defined in an injected and a "classic" way, and these can be mixed. Task values can be a literal, a function or a function returning a promise, and will behave as expected.
In the injected way, the parameters of task functions are parsed out and matched to task keys:
auto({
...
taskX: function(taskY) { return taskY; },
...
})
This is equivalent to the following definition in classic mode.
auto({
...
taskX: ['taskY', function(results) { return results.taskY; }]
...
})
auto({
task1: 'Hello',
task2: task1 => {
return ' world';
},
task3: (task1, task2) => new Promise((resolve, reject) => resolve('!')),
task4: (task1, task2, task3) => task1 + task2 + task3
}).then(results => {
console.log(results);
/*
Results are now. {
task1: 'Hello',
task2: ' world',
task3: '!',
task4: 'Hello world!'
*/
});