const delay = (ms, val) => new Promise(res => setTimeout(res, ms, val));
async function pipeline(...fns) {
return async (input) => {
let result = input;
for (const fn of fns) {
result = await fn(result);
}
return result;
};
}
const double = async (x) => delay(10, x * 2);
const addTen = async (x) => delay(10, x + 10);
const square = async (x) => delay(10, x ** 2);
(async () => {
const process = await pipeline(double, addTen, square);
const output = await process(3);
console.log(output);
})();
Post #3188
2.42K
CHALLENGE
- ❤ 2
- 🔥 2
- 👍 1