Skip to content

Instantly share code, notes, and snippets.

@ahgood
Created November 14, 2017 11:09
Show Gist options
  • Save ahgood/4cf5432198ffc95d4260eb0dc0344ce8 to your computer and use it in GitHub Desktop.
Save ahgood/4cf5432198ffc95d4260eb0dc0344ce8 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/hogapop
<!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>
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