awaits
v1.0.2
Published
await for many promise with high performance
Downloads
3
Maintainers
Readme
support nodejs 6.x and up
npm install awaits --save
awaits
await for many promise with high performance like nodejs async/await
samples:
// ES6
let awaits = require('awaits');
let procs = [];
procs.push(new Promise((rel) => {
setTimeout(() => {
rel('4000');
}, 4000);
}));
procs.push(new Promise((rel) => {
setTimeout(() => {
rel('2000');
}, 2000);
}));
// test catch
procs.push(new Promise((rel, ref) => {
setTimeout(() => {
ref('5000 catched');
}, 5000);
})); // (1)
console.log('waiting');
let st = new Date().getTime();
awaits(procs).then((rs) => {
console.log('time for run:', new Date().getTime() - st);
console.log(rs);
// check catched
if(rs[2].isCatched) {
//(1) catch
console.log(rs[2].error) // or .err .data .catch to get catch message
}
});
result:
waiting
time for run: 4994
[ '4000',
'2000',
{ isCatched: true,
data: '5000 catched',
err: '5000 catched',
error: '5000 catched',
catch: '5000 catched' } ]
5000 catched