Is there a function in jquery that returns a promise if at least one of Deferreds is resolved? -
i searched jquery documentation can't find function has same goal jquery.when() needs @ least 1 deferred resolved( not jquery.when() ) resolved?
i don't think there's .race
in jquery's promise implementation, use lightweight promise implementation (i.e. promise.js
) so:
var 1 = promise.resolve($.ajax(/*whatevs*/)); var 2 = promise.resolve($.ajax(/*sth else*/)); promise.race([one,two]).then(function(winner){ // whatever });
see mdn docs , promise.js
alternatively use deferred.progress
.notfiy
in jquery (although feels pretty awkward):
var 1 = $.deferred(function(dfd){ settimeout(function(){ dfd.notify('foo'); dfd.resolve('foo'); }, 200); }); var 2 = $.deferred(function(dfd){ settimeout(function(){ dfd.notify('bar'); dfd.resolve('bar'); }, 100); }); $.when(one, two).progress(function(onenotification, twonotification){ console.log(onenotification, twonotification); }).then(function(oneresult, tworesult){ console.log(oneresult, tworesult); });
Comments
Post a Comment