1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
function f1(ret) { return new Promise(function (resolve, reject) { setTimeout(() => { if (ret) resolve(ret) else reject('err'); }, 1000) }); }
async function f2() { let rets = await Promise.all([f1('f1_1'), f1('f1_2')]); return rets; }
f2() .then(console.log) .catch(console.error);
co(function* () { let rets = yield Promise.all([f1('f1_1'), f1('f1_2')]); return rets; }) .then(console.log) .catch(console.error);
|