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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -