1.0.4 • Published 9 years ago
promiss v1.0.4
Promiss
This is a promises sequence runner. It will be used to run multiple promise based functions in sequence.
Usage
Installation
npm install --save promissUsage
promiss takes two arguments.
arrayofpromisesoptionsto customize response
const promiss = require('promiss');
const foo = () => {
return Promise((resolve, reject) => {
setTimeout((){
resolve('hello');
}, 3000)
});
};
const bar = () => {
return Promise((resolve, reject) => {
setTimeout((){
reject(new Error('My heart broke'));
}, 5000)
});
};
const zoo = () => {
return Promise((resolve, reject) => {
setTimeout((){
resolve('adios');
}, 2000)
});
};
// throws the first error rejected
// same as passing { errors: true } as the second argument
return promiss([foo(), bar(), zoo()]).catch(err => {
// err.message = 'My heart broke'
// catches the first error
});
// collects all errors and resolves at the end with results
return promiss([foo, bar, zoo], { error: false }).then(results => {
// result will look like this
[
{
index: 0,
result: 'hello',
error: null
},
{
index: 1,
result: null,
error: Error('My heart broke')
},
{
index: 3,
result: 'adios',
error: null
}
]
});Options
errorstakesbooleanvalue:true: throws the first instance of error (the default behavior)false: collects all the errors and returns array of objects withindex,resultanderror-index: index of the method in the array passed -result: result if there is result andnullif it throws an error -error: error if there is error andnullif there is no error