Last active
December 21, 2015 08:29
-
-
Save m4r00p/6278718 to your computer and use it in GitHub Desktop.
Looped deferred
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getDeferred = function (i) { | |
var deferred = new $.Deferred(); | |
setTimeout(function () { | |
if (--i) { | |
deferred.resolve(i); | |
} else { | |
deferred.reject(i); | |
} | |
}, 2000); | |
return deferred.promise(); | |
}; | |
var done = function (i) { | |
console.log('done', i); | |
getDeferred(i).done(loop).fail(function () { | |
console.log('fail'); | |
}).always(function () { | |
console.log('always'); | |
}); | |
}; | |
done(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment