Created
February 16, 2010 00:08
-
-
Save kriskowal/305128 to your computer and use it in GitHub Desktop.
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 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