Skip to content

Commit

Permalink
Merge pull request #4 from sharkcore/remove_listeners
Browse files Browse the repository at this point in the history
remove listeners
  • Loading branch information
magicmark authored Nov 30, 2017
2 parents 5706348 + 8477cde commit 68f1fcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
any: build

.PHONY: test
test:
test: node_modules
yarn run lint
yarn test

Expand Down
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@ export default function tweenz(...tweens): Middleware {

// Construct a Promise to be fulfilled when request has completed
const requestDetails = new Promise(resolve => {
res.on('finish', () => {
function finish() {
resolve(context);
});
// eslint-disable-next-line no-use-before-define
removeListeners();
}

function removeListeners() {
res.removeListener('finish', finish);
res.removeListener('error', removeListeners);
res.removeListener('close', removeListeners);
}

res.once('finish', finish);
res.once('error', removeListeners);
res.once('close', removeListeners);
});

// Call each tween body
Expand Down

0 comments on commit 68f1fcc

Please sign in to comment.