Created
March 11, 2015 08:02
-
-
Save danharper/e4b6f7759b13e5e72bb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function sleep(ms) { | |
return new Promise(r => setTimeout(r, ms)) | |
} | |
async function foo() { console.log('s foo'); await sleep(2000); console.log('d foo'); return 'foo'; } | |
async function bar() { console.log('s bar'); await sleep(1000); console.log('d bar'); return 'bar'; } | |
async function baz() { console.log('s baz'); await sleep(2000); console.log('d baz'); return 'baz'; } | |
async function run() { | |
console.log('start') | |
var a = [foo(), bar(), baz()] | |
a.forEach(async (d) => { | |
let x = await d | |
console.log(x) | |
}) | |
console.log('done') | |
} | |
async function run2() { | |
console.log('start') | |
var a = [foo(), bar(), baz()] | |
for (let d of a) { | |
let x = await d | |
console.log(x) | |
} | |
console.log('done') | |
} | |
async function run3() { | |
console.log('start') | |
var a = [foo(), bar(), baz()] | |
await* a.map(async d => { | |
let x = await d | |
console.log(x) | |
}) | |
console.log('done') | |
} | |
run3() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment