Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 69x 69x 1047x 1047x 1043x 1043x 1043x 69x 69x 69x | /* eslint-disable no-param-reassign */
import timer from './timer';
// wrapTimer keeps track of the timing of a async operation and emits
// a event on the given eventBus once the operation is complete
//
// the returned function is designed to be used as a .then(<func>) argument.
// It transparently passes the data to the following .then(<func>)
//
// usage: promise.then(wrapTimer(bus, type, { payload: 'ok' }))
const wrapTimer: (EventEmitter, string, object) => (any) => any = (
eventBus,
event,
args = {},
) => {
const t = timer.new();
return (data) => {
args.time = t();
eventBus.emit(event, args);
return data;
};
};
const metricsHelper = {
wrapTimer,
};
export default metricsHelper;
module.exports = {
wrapTimer,
};
|