const delay = (val) => Promise.resolve(val);
async function pipeline(input) {
const result = await delay(input)
.then((v) => v * 2)
.then((v) => v + 10)
.then((v) => {
if (v > 20) throw new Error(`Too large: ${v}`);
return v;
})
.catch((e) => `Caught: ${e.message}`)
.then((v) => (typeof v === "string" ? v.toUpperCase() : v * 3));
return result;
}
Promise.all([pipeline(4), pipeline(8)]).then(([a, b]) => {
console.log(a);
console.log(b);
});
Post #3135
2.35K
CHALLENGE
- ❤ 2
- 👍 1