Opened 7 years ago
Closed 5 years ago
#17532 closed defect (patchwelcome)
dojo/promise/all should allow some resolved & some rejected with always()
Reported by: | Arlo White | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.13 |
Component: | Core | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
I have a situation where I'm merging results from two requests and if one fails I want to be able to continue. I'd expect always() to allow something like this, but it does not provide an array, instead I just get a single error if one Promise is rejected.
I want to do something like this:
all([request1, request2]).always(function(results){ var result1 = results[0]; if(!result1){ throw new Error('This data is required.'); } var result2 = results[2]; if(result2){ // Resolved, use the data... } });
Change History (4)
comment:1 Changed 7 years ago by
comment:2 Changed 7 years ago by
In your example, how would the callback function passed to "always" detect if a promise was resolved or rejected? Or would you only pass resolved promises to the callback?
comment:3 Changed 7 years ago by
In my hypothetical example, result1 is required, but the code can continue/recover if result2 is missing.
result2 would be null, undefined, or maybe the Error object? I'm not sure on the best design. Having access to the Error might be useful, but the code is a bit more complex that way.
if(result1 instanceof Error){ // result1 is required for this code. throw result1; } // result2 is optional if(!(result2 instanceof Error)){ // result2 successfully retrieved. }
comment:4 Changed 5 years ago by
Milestone: | tbd → 1.12 |
---|---|
Resolution: | → patchwelcome |
Status: | new → closed |
Given that no one has shown interest in creating a patch in the past 2+ years, I'm closing this as patchwelcome. Please let us know if you would like to get involved in helping make this change to Dojo!
This is my workaround, which really isn't so bad. Still, this would be a nice feature.