Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var delay = function (timeout) {
var deferred = new Deferred();
setTimeout(function () {
deferred.resolve();
}, timeout);
return deferred.promise;
};
delay(1000).then(function () {
// time flies
});
// and, equivalently
when(delay(1000), function () {
// time flies
});
// which is important for immediately
// resolvable values, the domain of
// all values and promises
when(10, function (n) {
// didn't have to wait a tick
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment