Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Created February 16, 2010 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriskowal/305128 to your computer and use it in GitHub Desktop.
Save kriskowal/305128 to your computer and use it in GitHub Desktop.
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