diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-03-25 17:39:41 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-03-25 17:39:41 -0300 |
commit | 3614ce99f2eaa910a2b11b0f2f4a8a291ee3a4b0 (patch) | |
tree | ac3a4bcfc988958ae7505b2f2d7dc24e9a8ca78e /util | |
parent | a90b90044fa6000bf0fa3490c20b6bf5c6502b1d (diff) |
fix ancient waitForData util listener memory leak
Particularly, this added a new event listener (i.e. function) every time the screen was resized, which would never be garbage collected. Oops.
Diffstat (limited to 'util')
-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) }) } |