Tap into a promise chain without affecting its value or state
npm install p-tap> Tap into a promise chain without affecting its value or state
```
$ npm install p-tap
`js
import pTap from 'p-tap';
Promise.resolve('unicorn')
.then(pTap(console.log)) // Logs unicornvalue
.then(value => {
// is still unicorn`
});
`js
import pTap from 'p-tap';
getUser()
.then(pTap(user => recordStatsAsync(user))) // Stats are saved about user async before the chain continuesuser
.then(user => {
// is the user from getUser(), not recordStatsAsync()`
});
`js
import pTap from 'p-tap';
Promise.resolve(() => doSomething())
.catch(pTap.catch(console.error)) // Prints any errors
.then(handleSuccess)
.catch(handleError);
`
Use this in a .then() method.
Returns a thunk that returns a Promise.
Use this in a .catch() method.
Returns a thunk that returns a Promise.
#### tapHandler
Type: Function
Any return value is ignored. Exceptions thrown in tapHandler are relayed back to the original promise chain.
If tapHandler returns a Promise`, it will be awaited before passing through the original value.
- p-log - Log the value/error of a promise
- p-if - Conditional promise chains
- p-catch-if - Conditional promise catch handler
- More…