1.0.7 • Published 5 years ago
promison v1.0.7
Expect to generate data from asynchronous apis like blow:
async function get() {
const result = {
v1: await Promise.resolve('v1'),
v2: { value: await Promise.resolve('v2') },
v3: { v3: [ 1, 2, 3 ].map(i => await Promise.resolve(i))},
};
return result;
}
In these codes, these promises will be executed one by one, not in a concurrent way.But if you use Promise.all, the code will be much more complicated because you hava to deal with the Promise.all's result array. Then let's try promison:
const promison = require('promison');
async function get() {
const data = {
v1: Promise.resolve('v1'),
v2: Promise.resolve({value: 'v2'}),
v3: { arr: [ 1, 2, 3 ].map(i => Promise.resolve(i))},
};
const result = await promison(data);
return result;
}
It's easy to use and the procedure will be much more clear.