Do something at every step in your promise chain.
npm install --save at-every-turn
Pass a function and an initial promise to atEveryTurn
. The function will be executed against the result of each promise in the ensuing promise chain - including the initial promise.
For example, executing this code:
const atEveryTurn = require('at-every-turn');
atEveryTurn(console.log, Promise.resolve(0))
.then((x) => x + 1)
.then((x) => x + 1);
Will produce this console output:
0
1
2
All promise behaviour is handled, including: catch
, the use of then
with onFulfilled
and onRejected
params, rejection of a then
and rejection of the initial promise.