Skip to content

Instantly share code, notes, and snippets.

@iMichaelOwolabi
Last active February 8, 2022 07:40
Show Gist options
  • Save iMichaelOwolabi/00b0ef1498b10d81f2e1039389a0b65c to your computer and use it in GitHub Desktop.
Save iMichaelOwolabi/00b0ef1498b10d81f2e1039389a0b65c to your computer and use it in GitHub Desktop.
Sample use of non-blocking promise implementation in Node.js
// Do this instead because unrelated awaits doesn't block each other ✅
const nonBlockinAsnycFunction = async () => {
// Start recording the execution time of the following code.
console.time('non-blocking-await');
const promise1 = samplePromise1();
const promise2 = samplePromise2();
// Use promise.all to ensure the two promises are executed in parallel.
const [promiseResult1, promiseResult2, promiseResult3] = await Promise.all([promise1, promise2, promise3]);
console.log(promiseResult1);
console.log(promiseResult2);
// Stop recording the execution time and log the elapsed time to the console.
console.timeEnd('non-blocking-await');
};
nonBlockinAsnycFunction();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment