Catching a Promise.all returns inconsistent data type
Reported by
thd...@gmail.com,
Aug 5 2016
|
||||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36 Steps to reproduce the problem: 1. Load vanilla_promises.html and open the console; you should see the "Images loaded" message with the URL array joined into two lines. 2. Now force one of both of the images to be broken by renaming .jpg to .jpgx or something. 3. What is the expected behavior? The catch() should also log an array to be consistent with the array that is returned when the Promise.all succeeds. What went wrong? The catch() logs a string. If both images are broken, it only logs the URL returned from the first reject(). This is inconsistent behavior. Did this work before? N/A Chrome version: 51.0.2704.103 Channel: n/a OS Version: 10.0 Flash Version: Shockwave Flash 22.0 r0
,
Aug 8 2016
,
Aug 9 2016
Sorry, I uploaded the wrong file -- please disregard that file and use this newly attached file instead (vanilla_promises2.html). The issue in a nutshell: when there is a "success" condition for the Promises.all, the callback returns an array (see the console output). Now try changing both image URLs from .jpg to .aaa or whatever to force an error condition. The expected out is that the error callback also returns an array, but instead it returns a string pass from the first rejected call.
,
Aug 11 2016
Is this working as intended?
,
Aug 11 2016
If this is by design, then please change this to an enhancement request. To have a consistent, predictable behavior, both success and error conditions should return either a string or an array (preferred), not one of each.
,
Aug 11 2016
The semantics of Promise.all make sense to me personally--if any fails, then Promise.all fails, and it doesn't wait for everything else to complete before it completes. It's possible to build basically any Promise combinator you want out of .then(). Promise.all has been shipped in several browsers, so I would have significant reservations from a web-compatibility perspective about changinging it. If you want different Promise functionality shipped by V8, the best thing to do would be to pursue it through the TC39 process. Promise.prototype.finally is in progress this way.
,
Aug 12 2016
@littledan Thanks for the reply; I see your point about potentially breaking existing apps. My use case was loading 10 images concurrently and giving the end user a report of all images that failed to load. I thought if I wanted to short-circuit, then I would use chaining. Since Promise.all also only reports the first error, then in this regards it is no different than chaining.
,
Aug 12 2016
thdoan, you can see the current specification at https://tc39.github.io/ecma262/#sec-promise.all . The logic is explicitly short-circuiting. Feel free to propose a new library feature to meet your different use case. |
||||
►
Sign in to add a comment |
||||
Comment 1 by msrchandra@chromium.org
, Aug 8 2016Labels: Needs-Feedback