Last active
February 9, 2022 11:35
-
-
Save iMichaelOwolabi/7d30c9e54dfe29bb142e76fa0528d92a to your computer and use it in GitHub Desktop.
Example promise in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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