diff options
-rw-r--r-- | util/waitForData.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/util/waitForData.js b/util/waitForData.js index bf40c52..ed88402 100644 --- a/util/waitForData.js +++ b/util/waitForData.js @@ -1,9 +1,11 @@ module.exports = function waitForData(stream, cond = null) { return new Promise(resolve => { - stream.on('data', data => { + const listener = data => { if (cond ? cond(data) : true) { resolve(data) + stream.removeListener('data', listener) } - }) + } + stream.on('data', listener) }) } |