Skip to content

Instantly share code, notes, and snippets.

@iMichaelOwolabi
Last active February 9, 2022 11:35
Show Gist options
  • Save iMichaelOwolabi/7d30c9e54dfe29bb142e76fa0528d92a to your computer and use it in GitHub Desktop.
Save iMichaelOwolabi/7d30c9e54dfe29bb142e76fa0528d92a to your computer and use it in GitHub Desktop.
Example promise in Node.js
/* Sample promises to simulate asynchronous operation.
* Let's assume these are sample DB operations and their equivalent response time
*
*/
const samplePromise1 = () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve('Promise 1 resolved after 2 seconds.');
}, 2000);
});
};
const samplePromise2 = () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve('Promise 2 resolved after 2 seconds.');
}, 2000);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment