Skip to content

Instantly share code, notes, and snippets.

@diversemix
Created November 13, 2019 15:56
Show Gist options
  • Save diversemix/60cfcfb4cd378744aa03004cc4799c42 to your computer and use it in GitHub Desktop.
Save diversemix/60cfcfb4cd378744aa03004cc4799c42 to your computer and use it in GitHub Desktop.
Test for understanding how blocking works
const log = console;
const sleep = async ms => {
return new Promise(resolve => setTimeout(resolve, ms));
};
const asyncFunc1 = async () => {
log.log('f1 Start');
await sleep(2000);
log.log('f1 End');
};
const asyncFunc2 = async () => {
log.log('f2 Start');
await sleep(1000);
log.log('f2 End');
};
console.log('### Startin...');
asyncFunc1();
console.log('### do another job....');
asyncFunc2();
console.log('### Stoppin...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment