Skip to content

Instantly share code, notes, and snippets.

@Mazuh
Created July 31, 2024 12:47
Show Gist options
  • Save Mazuh/65547c56d56e9c0fd7842f8382e0bb44 to your computer and use it in GitHub Desktop.
Save Mazuh/65547c56d56e9c0fd7842f8382e0bb44 to your computer and use it in GitHub Desktop.
Chained promises example
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