-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promise.tap #116
Promise.tap #116
Comments
To be fair I'm not sure why we have It is of course very possible to do this from your side just like you described: Promise.prototype.tap = function(fn){
return this.then(function(value){
fn(obj);
return obj;
});
}; |
Fair enough. Thanks! |
I like this function... Here is one use case: cache.get('foo')
.then(foo => foo ? foo : db.get('foo').tap(cache.put))
.then(res.json); vs cache.get('foo')
.then(foo => foo ? foo : db.get('foo').then(foo => cache.put(foo).thenReturn(foo)))
.then(res.json); Can you come up with other cases? :) |
Passing |
FWIW I use login: function(body) {
return new User({email: body.email})
.fetch({require: true})
.tap(function(user) {
return bcrypt.compareAsync(body.password, user.password);
})
.then(function(user) {
return user.id
});
} |
@tgriesser why are you calling compare but not doing anything with the result? :P |
Because I don't need to do anything with it, it's purely called to ensure it doesn't throw (if the password is wrong). |
Yup, just today I wrote this:
Note second |
This is in 1.1 |
It would be nice for quick debugging for a
.tap
function to exist, such that.then(function(obj) { tapFn(obj); return obj })
could be replaced by
.tap(tapFn)
Thanks!
The text was updated successfully, but these errors were encountered: