Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Allow hooks to return a promise #3

Closed
daffl opened this issue Jun 4, 2014 · 0 comments · Fixed by #4
Closed

Allow hooks to return a promise #3

daffl opened this issue Jun 4, 2014 · 0 comments · Fixed by #4

Comments

@daffl
Copy link
Member

daffl commented Jun 4, 2014

I want to be able to return a promise from a hook. Promise return values should not be used so that we can do things like:

userService.before({
    remove: function(hook) {
        // Delete the user from intercom.io first
        return Q.ninvoke(intercom, 'deleteUser', { user_id: hook.id });
    }
});

If you want to modify hook data, just change it after .then:

userService.before({
  remove: function(hook) {
    // Delete the user from intercom.io first
    return Q.ninvoke(intercom, 'deleteUser', { user_id: hook.id }).then(function(user) {
      hook.id = user.id;
    });
  }
});

Errors in the promise will be treated as actual errors.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant