Skip to content

Instantly share code, notes, and snippets.

@YashdalfTheGray
Last active November 10, 2015 05:05
Show Gist options
  • Save YashdalfTheGray/504abce74e073ce5c7b7 to your computer and use it in GitHub Desktop.
Save YashdalfTheGray/504abce74e073ce5c7b7 to your computer and use it in GitHub Desktop.
Wrapping other async tasks
// assume that getUsers returns a promise but
// the service may not be written in angular
$q.when(service.getUsers()).then(function(result) {
ctrl.userList = result;
});
// $q.when() can also be useful when writing stubs
function getUsers() {
// this function is supposed to return a promise
// but in test, it doesn't make sense to do that
// so use $q.when() to return an immediately
// resolving promise.
return $q.when(_userList);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment