1: Use promise to implement promise.all(), promise.allSettle(), promise.race().
2. Implement a class named Flow{} that fulfills the following:
const flow = new Flow();
flow
.step((next) => {
setTimeout(() => {
next("foo");
}, 1000);
})
.step((next, value) => {
setTimeout(() => {
next(`${value}-bar`);
}, 500);
})
.execute((value) => {
console.log(value); // Expected Output: "foo-bar"
});
The basic idea is to use a promise chain, where step creates a new promise stored in an array, and execute calls this promise chain.