Proposal: `await.all {...}` for parallelism
manuelbarzi
manuelbarzi at gmail.com
Mon Nov 25 16:41:51 UTC 2019
>
> Hi Manuel! Would you mind explaining the added value of your proposal? I
> am only seeing it being more verbose, but I've not found any added
> functionality or benefit from it
>
the proposal combines parallel and series async / await and could resolve
complex trees, like the following example:
```
// NOTE async {} = asynchronous scope (it groups parallel awaits => `await||`)
// NOTE p? = function call that returns a promise (? = just and index)
async {
const x1 = await|| p1()
const x2 = await p2(x1)
const x3 = await|| p3()
const x10 = await p10(x2, x3)
let x4, x5, x6
async {
x4 = await|| p4(x1, x2)
x5 = await|| p5(x2, x3)
x6 = await p6(x4, x5, x10)
}
let x7, x8, x9
async {
x7 = await|| p7(x4, x6)
x8 = await p8(x6, x7)
x9 = await|| p9(x5, x6)
}
await p11(x8, x9)
}
// it would resolve a tree of parallel and series like following with
traditional promises
Promise.resolve()
.then(() => Promise.all([p1, p3]))
.then((x1, x3) =>
p2(x1)
.then(x2 =>
p10(x2, x3)
.then(x10 => {
let x4, x5, x6
return Promise.resolve()
.then(() => Promise.all([p4(x1, x2), p5(x2, x3
)]))
.then(results => [x4, x5] = results)
.then(() => p6(x4, x5, x10))
.then(x6 => {
let x7, x8, x9
return Promise.resolve()
.then(() => Promise.all([p7(x4, x6), p9(
x5, x6)]))
.then(results => [x7, x9] = results)
.then(() => p8(x6, x7))
.then(_x8 => x8 = _x8)
.then(() => p11(x8, x9))
})
})
)
)
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20191125/2f64ccdf/attachment.html>
More information about the es-discuss
mailing list