JavaScript For of Await

node v17.9.1
version: 5.0.0
endpointsharetweet
const one = () => { return new Promise((resolve) => { setTimeout(() => resolve(2), 2000); }) }; const two = () => { return new Promise((resolve, reject) => { setTimeout(() => reject(3), 3000); }) }; const three = () => { return new Promise((resolve) => { setTimeout(() => resolve(5), 5000); }) }; const arr = () => { return [one(), two(), three()]; } // This is only needed in NodeJS (async () => { try { for await (const result of arr()) { console.log('result:', result) } } catch (e) { console.log('caught', e); } })();
Loading…

no comments

    sign in to comment