Created
November 14, 2017 11:09
-
-
Save ahgood/4cf5432198ffc95d4260eb0dc0344ce8 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/hogapop
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function doubleAfter2Seconds(x) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(x * 2); | |
}, 2000); | |
}); | |
} | |
async function addAsync(x) { | |
const a = doubleAfter2Seconds(10); | |
const b = doubleAfter2Seconds(20); | |
const c = doubleAfter2Seconds(30); | |
// Place all awaits on the same line | |
// so that they're handled in parallel | |
// like promise.all. | |
return x + (await a) + (await b) + (await c); | |
} | |
addAsync(5).then(result => { | |
console.log(result); | |
}); | |
//console.log(addAsync(5)); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> function doubleAfter2Seconds(x) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(x * 2); | |
}, 2000); | |
}); | |
} | |
async function addAsync(x) { | |
const a = doubleAfter2Seconds(10); | |
const b = doubleAfter2Seconds(20); | |
const c = doubleAfter2Seconds(30); | |
// Place all awaits on the same line | |
// so that they're handled in parallel | |
// like promise.all. | |
return x + (await a) + (await b) + (await c); | |
} | |
addAsync(5).then(result => { | |
console.log(result); | |
}); | |
//console.log(addAsync(5));</script></body> | |
</html> |
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
function doubleAfter2Seconds(x) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(x * 2); | |
}, 2000); | |
}); | |
} | |
async function addAsync(x) { | |
const a = doubleAfter2Seconds(10); | |
const b = doubleAfter2Seconds(20); | |
const c = doubleAfter2Seconds(30); | |
// Place all awaits on the same line | |
// so that they're handled in parallel | |
// like promise.all. | |
return x + (await a) + (await b) + (await c); | |
} | |
addAsync(5).then(result => { | |
console.log(result); | |
}); | |
//console.log(addAsync(5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment