Re: Intent to ship: Promise.allSettled

2019-11-02 Thread Paolo Amadini
On 11/1/2019 2:42 PM, Jan-Ivar Bruaroey wrote: My original point was that the semantics of Promise.allSettled, which are "keep waiting for the lot even if some async operations fail", did not deserve its own standard name in the JS language, because of A) how rarely this is actually what you w

Re: Consider avoiding allSettled in tests (was: Re: Intent to ship: Promise.allSettled)

2019-11-01 Thread Kris Maglione
On Thu, Oct 31, 2019, 06:02 Jason Orendorff wrote: > Ignoring the awaited value here is like using `catch {}` to squelch all > exceptions, or ignoring the return value of an async function or method, or > any other expression that produces a Promise. Do we have lints for those > pitfalls? I'm kin

Re: Intent to ship: Promise.allSettled

2019-11-01 Thread Jan-Ivar Bruaroey
On 11/1/19 6:08 AM, Paolo Amadini wrote: On 10/31/2019 1:57 PM, Jan-Ivar Bruaroey wrote: The context here is the same as Promise.allSettled: we explicitly *do* want to ignore errors, right? In general, in mozilla-central we want to at least log those errors, at which point they are already cau

Re: Intent to ship: Promise.allSettled

2019-11-01 Thread Paolo Amadini
On 10/31/2019 1:57 PM, Jan-Ivar Bruaroey wrote: The context here is the same as Promise.allSettled: we explicitly *do* want to ignore errors, right? In general, in mozilla-central we want to at least log those errors, at which point they are already caught, and using "Promise.all" is then equiv

Re: Intent to ship: Promise.allSettled

2019-10-31 Thread Jan-Ivar Bruaroey
On 10/31/19 4:26 AM, Paolo Amadini wrote: On 10/30/2019 10:19 PM, Jan-Ivar Bruaroey wrote: Promise.all(promises.map(p => p.catch(e => e))) https://stackoverflow.com/questions/31424561/wait-until-all-promises-complete-even-if-some-rejected/36115549#36115549 By the way, this "catch(e => e

Re: Consider avoiding allSettled in tests (was: Re: Intent to ship: Promise.allSettled)

2019-10-31 Thread Jason Orendorff
On Thu, Oct 31, 2019 at 4:10 AM Paolo Amadini wrote: >// INCORRECT >//await Promise.allSettled([promise1, promise2]); > > The last example silently loses any rejection state. > Ignoring the awaited value here is like using `catch {}` to squelch all exceptions, or ignoring the return valu

Re: Intent to ship: Promise.allSettled

2019-10-31 Thread Paolo Amadini
On 10/30/2019 10:19 PM, Jan-Ivar Bruaroey wrote:     Promise.all(promises.map(p => p.catch(e => e))) https://stackoverflow.com/questions/31424561/wait-until-all-promises-complete-even-if-some-rejected/36115549#36115549 By the way, this "catch(e => e)" call may make sense as an example in the

Consider avoiding allSettled in tests (was: Re: Intent to ship: Promise.allSettled)

2019-10-31 Thread Paolo Amadini
On 10/30/2019 10:19 PM, Jan-Ivar Bruaroey wrote: This always seemed trivial to me to do with:     Promise.all(promises.map(p => p.catch(e => e))) As Boris pointed out, this does not have proper exception handling. If exceptions should be ignored, it may be good to call "console.error". In case

Re: Intent to ship: Promise.allSettled

2019-10-30 Thread Jan-Ivar Bruaroey
Promise.any is an inverse of Promise.all, right? There and back again: Promise.all(promises.map(p => p.then(r => Promise.reject(r), e => e))) .then(r => Promise.reject(r), e => e) https://jsfiddle.net/jib1/f085bcyk/ That said, Promise.any has a nice ring to it. .: Jan-Ivar :. On 10/30/19 6:

Re: Intent to ship: Promise.allSettled

2019-10-30 Thread Jan-Ivar Bruaroey
Yes, it would have been clever of me to predict the semantics 3 years ago. ;-) But as I mention in the stackoverflow post, depending on context and the type(s) of values expected, errors can often be distinguished easily enough in practice, if not in general. That said, I've never actually h

Re: Intent to ship: Promise.allSettled

2019-10-30 Thread Boris Zbarsky
On 10/30/19 6:19 PM, Jan-Ivar Bruaroey wrote: This always seemed trivial to me to do with:     Promise.all(promises.map(p => p.catch(e => e))) This has different semantics from Promise.allSettled, right? In particular, it effectively treats rejected promises as resolved with the rejection

Re: Intent to ship: Promise.allSettled

2019-10-30 Thread Jason Orendorff
On Wed, Oct 30, 2019 at 5:20 PM Jan-Ivar Bruaroey wrote: > This always seemed trivial to me to do with: > > Promise.all(promises.map(p => p.catch(e => e))) > I guess it depends on your definition of "trivial". If everyone knows de Morgan's laws, we don't need *both* `||` and `&&` operators.

Re: Intent to ship: Promise.allSettled

2019-10-30 Thread Jim Blandy
Every new primitive is a nail in the coffin of the next attempt to build a new competitive web browser. (Distraught voice: "Won't they think of the Servos?!?") On Wed, Oct 30, 2019 at 3:20 PM Jan-Ivar Bruaroey wrote: > This always seemed trivial to me to do with: > > Promise.all(promises.m

Re: Intent to ship: Promise.allSettled

2019-10-30 Thread Jan-Ivar Bruaroey
This always seemed trivial to me to do with: Promise.all(promises.map(p => p.catch(e => e))) https://stackoverflow.com/questions/31424561/wait-until-all-promises-complete-even-if-some-rejected/36115549#36115549 But I guess it's too late to make that point. I guess the more primitives the m

Intent to ship: Promise.allSettled

2019-10-30 Thread Jason Orendorff
In Firefox 71, we'll ship Promise.allSettled, a standard way to `await` several promises at once. André Bargull [:anba] contributed the implementation of this feature. It's in Nightly now. Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1539694 Shipped in: https://bugzilla.mozilla.org/show_bug.c