Skip to content

Instantly share code, notes, and snippets.

@yussan
Created May 30, 2020 04:26
Show Gist options
  • Save yussan/8b6452dcdcb8fdb06e9abb7ed33fc74b to your computer and use it in GitHub Desktop.
Save yussan/8b6452dcdcb8fdb06e9abb7ed33fc74b to your computer and use it in GitHub Desktop.
sample script with and without Async Await
async function start() {
let x1 = await exe(1);
console.log("x1", x1);
let x2 = await exe(2);
console.log("x2", x2);
}
function exe(n) {
return new Promise((resolve, reject) => {
let response;
setTimeout(() => {
response = `Success ${n}`;
resolve(response);
}, 1000);
});
}
start();
function start() {
let x1 = exe(1);
console.log("x1", x1);
let x2 = exe(2);
console.log("x2", x2);
}
function exe(n) {
let response;
setTimeout(() => {
response = `Success ${n}`;
}, 1000);
return response;
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment