Skip to main content

Bug Tracker

Side navigation

#14117 closed feature (duplicate)

Opened July 09, 2013 01:36PM UTC

Closed July 09, 2013 02:08PM UTC

Last modified July 09, 2013 02:59PM UTC

Allow an array of deferreds as first argument to .when()

Reported by: Tomalak Owned by:
Priority: low Milestone: None
Component: deferred Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:
Description

This is a feature proposal for the Deferred module.

.when()
currently only supports a list of (any number of) individual arguments.

I've been in the situation where I have an array of deferred objects, most commonly a list of pending Ajax calls, which forces me to make use of a construct like

jQuery.when.apply(jQuery, array)
in order to pass them to
.when()
.

It should be possible to pass an array of deferreds directly to

.when()
as its only argument, like this
jQuery.when(array)
.

The source code (https://github.com/jquery/jquery/blob/master/src/deferred.js#L93) shows that it would be possible to extend

.when()
in that way through a trivial change and without breaking existing functionality.

I've created a pull request that shows the change https://github.com/jquery/jquery/pull/1304

Attachments (0)
Change History (8)

Changed July 09, 2013 01:45PM UTC by timmywil comment:1

component: unfileddeferred
keywords: → 1.11-discuss
priority: undecidedlow
status: newopen

I like this. My main use of when is $.when.apply.

Changed July 09, 2013 01:54PM UTC by markelog comment:2

_comment0: Me too, i also use that a lot, anologue of {{{Q.all/when.all}}} might be pretty useful, but from [http://api.jquery.com/jQuery.when jQuery.when] doc: \ > If a single argument is passed to jQuery.when and it is not a Deferred or a Promise, it will be treated as a resolved Deferred and any doneCallbacks attached will be executed immediately. \ \ Although i doubt any code depend on that feature. \ \ @Tomalak, BTW when you submitting a pull request, in addition to source changes and ticket number, you should also have tests that support new functionality and signed [http://contribute.jquery.org/CLA/ CLA], see [http://contribute.jquery.org this] site for more information.1373378134147818

Me too, i also use

$.when.apply
a lot, anologue of
Q.all/when.all
might be pretty useful, but from jQuery.when doc:

If a single argument is passed to jQuery.when and it is not a Deferred or a Promise, it will be treated as a resolved Deferred and any doneCallbacks attached will be executed immediately.

Although i doubt any code depend on that feature.

@Tomalak, BTW when you submitting a pull request, in addition to source changes and ticket number, you should also have tests that support new functionality and signed CLA, see this site for more information.

Changed July 09, 2013 02:04PM UTC by scottgonzalez comment:3

Although i doubt any code depend on that feature.

Why would you doubt that? It's a pretty powerful and common feature. There's a reason that Q.all() has to exist, and it's because Q() will accept any single value just like jQuery.when().

I don't see how we can even be considering this.

Changed July 09, 2013 02:08PM UTC by rwaldron comment:4

resolution: → duplicate
status: openclosed

Duplicate of #8256.Sorry dudes...

Changed July 09, 2013 02:13PM UTC by timmywil comment:5

keywords: 1.11-discuss

Sorry, I missed that ticket 18 months ago.

Changed July 09, 2013 02:16PM UTC by rwaldron comment:6

Replying to [comment:5 timmywil]:

Sorry, I missed that ticket 18 months ago.

No worries ;)

Changed July 09, 2013 02:40PM UTC by Tomalak comment:7

Ah damn, it seemed like such a good idea.

Changed July 09, 2013 02:59PM UTC by jaubourg comment:8

I'm not against a $.whenAll thingy. It's just that we wouldn't be using it in core.