Created
July 31, 2024 12:47
-
-
Save Mazuh/65547c56d56e9c0fd7842f8382e0bb44 to your computer and use it in GitHub Desktop.
Chained promises example
This file contains 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
const delayedPrint = (content) => new Promise(r => setTimeout(() => r() & console.log(content), 1000)); | |
await ["João", "Maria", "todo mundo"].reduce( | |
(chained, n) => chained.then(() => delayedPrint(`Oi, ${n}!`)), | |
Promise.resolve() | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment