From 810e118c32e15d9e7216a2694566373ac109a7f9 Mon Sep 17 00:00:00 2001 From: Ruslan Kerimov Date: Fri, 17 May 2019 12:49:03 +0300 Subject: [PATCH] fix event name `cancel` => `close` --- index.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7850512..c6fc0fb 100644 --- a/index.js +++ b/index.js @@ -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(); }; };