OK I'm even more confused now. x1 is surely not a resolved value until all the next "non parallel await" so is it "undefined" until then?
Could you give an example of what you mean by the `await.all { ... }` block syntax bringing "complexity on returning values assignment, specially when" "about constants (`const`)", as I'm unclear what you are referring to. Cheers, N On Tue, 26 Nov 2019 at 13:35, manuelbarzi <manuelba...@gmail.com> wrote: > > >> Why not just maximally preserve current JavaScript for parallel >> execution, just by omitting `await` in multiple async calls, simply >> wrapping it in an `await.all` block to ensure completion before code >> continues past the block. This surely is the more straightforward way to >> satisfy the same goals? >> > > because wrapping it an `await.all` on the one hand explicitly groups > promises, but brings complexity on returning values assignment, specially > when is about constants (`const`). so, if you avoid blocks, just marking > parallel awaits with, for example, a suffix `await||`, or whatever other > more convenient way, you can just write the code in series as normally, and > avoid that complexity. the transpiler would just require to group the > consecutive marked parallel awaits (`await||`) into a Promise.all() and > that's it. following i reproduce the demo before: > > ``` > // NOTE p? = function call that returns a promise (? = just and index) > > // NOTE s? = function call that runs synchronously and returns a value (? = > just and index) > > const x0 = await p0() > > const x11 = s11() // sync code in-the-middle > > const x1 = await || p1(x0) > const x3 = await || p3(x11) > const x2 = await p2(x1) > const x10 = await p10(x2, x3) > > const x12 = s12() // sync code in-the-middle > > const x4 = await || p4(x1, x2) > const x5 = await || p5(x2, x3, x12) > const x6 = await p6(x4, x5, x10) > > const x7 = await || p7(x4, x6) > const x9 = await || p9(x5, x6) > const x8 = await p8(x6, x7) > > await p11(x8, x9) > > > // it would resolve a tree of parallel and series like following with > traditional promises > > p0 > .then(x0 => { > const x11 = f11() > > return Promise.all([p1(x0), p3(x11)]) > .then((x1, x3) => > p2(x1) > .then(x2 => > p10(x2, x3) > .then(x10 => { > const x12 = s12() > > return Promise.all([p4(x1, x2), p5(x2, x3 > , x12)]) > .then((x4, x5) => > p6(x4, x5, x10) > .then(x6 => Promise.all([p7(x4 > , x6), p9(x5, x6)]) > .then((x7, x9) => p8(x6, > x7) > .then(x8 => p11(x8, x9 > )) > ) > ) > ) > }) > ) > ) > }) > ``` >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss