Skip to content

Instantly share code, notes, and snippets.

@anttispitkanen
Last active May 25, 2021 09:46
Show Gist options
  • Save anttispitkanen/528c5d20b8319aa8aaa8f4418eb9a5be to your computer and use it in GitHub Desktop.
Save anttispitkanen/528c5d20b8319aa8aaa8f4418eb9a5be to your computer and use it in GitHub Desktop.
What happens to the first async function (waitAndReturn) invocation?
const waitAndReturn = (ms, msg) =>
new Promise(resolve => {
setTimeout(() => {
resolve(msg);
}, ms);
});
const foo = () => {
waitAndReturn(5000, 'First').then(msg => console.log(msg));
return waitAndReturn(300, 'Second');
};
const main = async () => {
console.log(await foo());
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment