Menu

gitpiper

runPromisesInSeries javascript Code Snippet in 2023

functionpromiseintermediate

Last Updated: 28 January 2023

Runs an array of promises in series.

  • Use Array.prototype.reduce() to create a promise chain, where each promise returns the next promise when resolved.
const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());
const delay = d => new Promise(r => setTimeout(r, d)); runPromisesInSeries([() => delay(1000), () => delay(2000)]); // Executes each promise sequentially, taking a total of 3 seconds to complete

javascript snippet similar to runPromisesInSeries For You in January 2023

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2023 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️