Skip to content

Commit

Permalink
fix event name cancel => close
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslankerimov committed May 17, 2019
1 parent d3dca78 commit 810e118
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ module.exports = function requestTimeMiddleware(label, cb) {

res
.on('finish', onFinish)
.on('cancel', onCancel);
.on('close', onClose);

function onFinish() {
unbind();

var timeObj = timerStop();
cb(timeObj.time, req);
}

function onCancel() {
res
.removeListener('cancel', onCancel)
.removeListener('finish', onFinish);
function onClose() {
unbind();

// FIXME: what should we do here?
cb(0, req);
}

function unbind() {
res
.removeListener('close', onClose)
.removeListener('finish', onFinish);
}

next();
};
};

0 comments on commit 810e118

Please sign in to comment.