Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14117 closed feature (duplicate)

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

Change History (8)

comment:1 Changed 6 years ago by timmywil

Component: unfileddeferred
Keywords: 1.11-discuss added
Priority: undecidedlow
Status: newopen

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

comment:2 Changed 6 years ago by markelog

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.

Last edited 6 years ago by markelog (previous) (diff)

comment:3 Changed 6 years ago by scottgonzalez

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.

comment:4 Changed 6 years ago by Rick Waldron

Resolution: duplicate
Status: openclosed

Duplicate of #8256.
Sorry dudes...

comment:5 Changed 6 years ago by timmywil

Keywords: 1.11-discuss removed

Sorry, I missed that ticket 18 months ago.

comment:6 in reply to:  5 Changed 6 years ago by Rick Waldron

Replying to timmywil:

Sorry, I missed that ticket 18 months ago.

No worries ;)

comment:7 Changed 6 years ago by Tomalak

Ah damn, it seemed like such a good idea.

comment:8 Changed 6 years ago by jaubourg

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

Note: See TracTickets for help on using tickets.