Skip to content

Instantly share code, notes, and snippets.

@ssd532
Last active March 7, 2020 05:37
Show Gist options
  • Save ssd532/6da73dba92959a2bf167e456a596dec4 to your computer and use it in GitHub Desktop.
Save ssd532/6da73dba92959a2bf167e456a596dec4 to your computer and use it in GitHub Desktop.
async/await JS Bin// source https://jsbin.com/milexor
<!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>
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