I don't think I like "await ||" as a syntax, because it doesn't have anything to do with the "OR" operator.
It does avoid adding a bunch of potentially optimization-breaking if statements to the transpiled output for synchronous code like in my example, though, because you only get the behavior for the promises you actually choose to collect with it. Manuel, I am not sure I understand your examples. You are consuming the values x1 and x2 in p4 right in the middle of the same async block that contains the "await ||" statements that produce them. They are not guaranteed to resolve until after that block is over, no? On Mon, Nov 25, 2019 at 12:05 PM manuelbarzi <[email protected]> wrote: > yet smaller, as Promise.resolve() was totally redundant here... > > > // 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) > } > > Promise.all([p1(), p3()]) > .then((x1, x3) => > p2(x1) > .then(x2 => > p10(x2, x3) > .then(x10 => { > let x4, x5, x6 > > return Promise.all([p4(x1, x2), p5(x2, x3)]) > .then(results => [x4, x5] = results) > .then(() => p6(x4, x5, x10)) > .then(_x6 => x6 = _x6) > .then(() => { > let x7, x8, x9 > > return 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)) > }) > }) > ) > ) > > On Mon, Nov 25, 2019 at 5:57 PM manuelbarzi <[email protected]> wrote: > >> a few little corrections... >> >> >> // 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) >> } >> >> 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 => x6 = _x6) >> .then(() => { >> 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)) >> }) >> }) >> ) >> ) >> >> >> >> >> On Mon, Nov 25, 2019 at 5:41 PM manuelbarzi <[email protected]> >> wrote: >> >>> 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)) >>> }) >>> }) >>> ) >>> ) >>> ``` >>> >>> >>> -- THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

