Skip to content

Instantly share code, notes, and snippets.

@bryanjknight
Last active March 29, 2018 10:31
Show Gist options
  • Save bryanjknight/819f6b1ade6c5677b8ad57d04da5a49d to your computer and use it in GitHub Desktop.
Save bryanjknight/819f6b1ade6c5677b8ad57d04da5a49d to your computer and use it in GitHub Desktop.
'use strict';
async function doSomething(waitTime) {
// because setTimeout does not return a promise (yet)
// we have to wrap it in a promise and wait for it to resolve
return new Promise(function(resolve) {
setTimeout(resolve, waitTime);
});
}
async function doEverything() {
let result = await doSomething(1000);
console.log(`Result #1: ${result}`);
result = await doSomething(2000);
console.log(`Result #2: ${result}`);
}
doEverything();
console.log('kicked off doEverything');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment