Last active
March 7, 2020 05:37
-
-
Save ssd532/6da73dba92959a2bf167e456a596dec4 to your computer and use it in GitHub Desktop.
async/await JS Bin// source https://jsbin.com/milexor
This file contains 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 name="description" content="async-await-blocking"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function getNumber(n) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log("Number is: " + n); | |
resolve(n); | |
}, 1000); | |
}); | |
} | |
async function test() { | |
let n1 = await getNumber(1); | |
console.log('am I printed yet?') | |
let n2 = await getNumber(2); | |
console.log('n1 is: ' + n1); | |
console.log('n2 is: ' + n2); | |
} | |
test() | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function getNumber(n) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log("Number is: " + n); | |
resolve(n); | |
}, 1000); | |
}); | |
} | |
async function test() { | |
let n1 = await getNumber(1); | |
console.log('am I printed yet?') | |
let n2 = await getNumber(2); | |
console.log('n1 is: ' + n1); | |
console.log('n2 is: ' + n2); | |
} | |
test() | |
</script></body> | |
</html> |
This file contains 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 getNumber(n) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log("Number is: " + n); | |
resolve(n); | |
}, 1000); | |
}); | |
} | |
async function test() { | |
let n1 = await getNumber(1); | |
console.log('am I printed yet?') | |
let n2 = await getNumber(2); | |
console.log('n1 is: ' + n1); | |
console.log('n2 is: ' + n2); | |
} | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment