Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Created May 23, 2024 19:24
Show Gist options
  • Save ChrisMoney/41001f27af44feb51a75b5eee8eead01 to your computer and use it in GitHub Desktop.
Save ChrisMoney/41001f27af44feb51a75b5eee8eead01 to your computer and use it in GitHub Desktop.
JS Await and Async
function resolveAfter2Seconds() {
return new Promise((resolve) => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
console.log('calling');
const result = await resolveAfter2Seconds();
console.log(result);
// Expected output: "resolved"
}
asyncCall();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment