Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $.when do for a single $.Deferred?

I'm trying to understand $.when, and I can see that it can be useful when you want to wait for multiple deferreds before proceeding. However, I'm not sure I understand what the use-case is for using $.when with one deferred. To illustrate:

var deferred = $.Deferred();

// Is this ever useful?
$.when(deferred).then(...)

// Or can I always do this?
deferred.then(...)
like image 314
Abdullah Jibaly Avatar asked Jun 06 '12 15:06

Abdullah Jibaly


People also ask

How does a single premium deferred annuity work?

A single-premium deferred annuity (SPDA) is an annuity established with a single payment featuring investment growth solely during the accumulation phase. That growth occurs on a tax-deferred basis until annuitization, at which time regular payments will begin.

How soon can the benefit payments begin with a deferred?

How soon can the benefit payments begin with a deferred annuity? Typically, payments can start as soon as two years after the policy issue date.

What are the benefits of a deferred?

A deferred compensation plan withholds a portion of an employee's pay until a specified date, usually retirement. The lump sum owed to an employee in this type of plan is paid out on that date. Examples of deferred compensation plans include pensions, 401(k) retirement plans, and employee stock options.

What happens if a deferred annuity?

Term Deferred Annuities A term deferred annuity is one that eventually turns your balance into a set number of payments, like over five years or 20 years. If you die during the term, the payments continue to your heirs. Once the term ends, though, the payments stop, even if you're still alive.


1 Answers

From the $.when [docs] documentation:

If a single Deferred is passed to jQuery.when, its Promise object (a subset of the Deferred methods) is returned by the method.

So $.when(deferred).then(...) is the same as deferred.promise().then(...).

The promise object is just a limited interface to the deferred object. It allows to add callbacks, but not to change the state of the Deferred (resolve, reject it).

So conclusively, there is basically no difference between using $.when and calling .then directly on the deferred object.

I don't think it makes sense to pass a single deferred object explicitly to $.when, since you don't get any advantage. However, there might be situations where you have an unknown number of deferred objects, which means it could also be only one.

like image 107
Felix Kling Avatar answered Sep 30 '22 02:09

Felix Kling