Bug Tracker

Modify

Ticket #10307 (closed enhancement: duplicate)

Opened 20 months ago

Last modified 4 months ago

$.when should accept array of deferreds

Reported by: gondo@… Owned by:
Priority: low Milestone: None
Component: deferred Version: 1.6.4
Keywords: Cc:
Blocking: Blocked by:

Description

$.when should accept array of deferreds as parameter. currently, it accepts just 1 deferred object or more arguments (more deferreds separated by comma)

Change History

comment:1 Changed 20 months ago by rwaldron

  • Priority changed from undecided to low
  • Resolution set to duplicate
  • Status changed from new to closed
  • Component changed from unfiled to deferred

comment:2 Changed 20 months ago by rwaldron

Duplicate of #8256.

comment:4 Changed 20 months ago by ajpiano

#10367 is a duplicate of this ticket.

comment:5 Changed 20 months ago by ajpiano

We don't intend to add this because the values that are passed to jQuery.when are not required to be observable - an array, like anything else besides a deferred or promise, is treated as something that has already been resolved. Another option like introspecting an array to check for the existence of deferreds is overly invasive and brittle, so I believe we'll continue to recommend using $.when.apply(null, arrayOfDeferreds). If you like, you can duckpunch it into your jQuery with something like

var oldWhen = jQuery.when;
jQuery.when = function( arg ) {
  if ( jQuery.isArray( arg ) ) {
    return oldWhen.apply( null, arg );
  } else {
    return oldWhen.apply( Array.prototype.slice.call( arguments ) );
  }
};

comment:6 Changed 4 months ago by anonymous

Not having a way to wait for an array of promises in jQuery is a huge drawback IMHO. In all the time I used $.when in almost all of them I have to use the apply invocation.

Only in the simplest of cases you will store your jqXHR in variables, because doing it that way does not scale for more than 3 or 4 instances and makes for hard to maintian/evolve code.

Both  https://github.com/kriskowal/q  https://github.com/cujojs/when and  https://github.com/kriszyp/node-promise support that syntax, and it is hard for me to see why jQuery does not.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.