Q:

Write a JavaScript program to run a given array of promises in series

0

Write a JavaScript program to run a given array of promises in series.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.resolve());
const delay = d => new Promise(r => setTimeout(r, d));

// Executes each promise sequentially, taking a total of 3 seconds to complete

runPromisesInSeries([() => delay(1000), () => delay(2000)]);

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now