Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@teropa
Created May 20, 2014 14:01
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 teropa/ddf94bf23fe9e8bdaded to your computer and use it in GitHub Desktop.
Save teropa/ddf94bf23fe9e8bdaded to your computer and use it in GitHub Desktop.
$q.now() - an immediately resolved promise oneliner for Angular.js
module.config(['$provide', function($provide) {
// Add a method to $q that returns a promise resolved to
// the given value. Use as: $q.now(42)
$provide.decorator('$q', ['$delegate', function($delegate) {
$delegate.now = function(value) {
var d = $delegate.defer();
d.resolve(value);
return d.promise;
};
return $delegate;
}]);
}]);
@teropa
Copy link
Author

teropa commented May 20, 2014

Or, as it turns out, you could just use when

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment