« get me outta code hell

tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/util/waitForData.js
diff options
context:
space:
mode:
Diffstat (limited to 'util/waitForData.js')
-rw-r--r--util/waitForData.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/util/waitForData.js b/util/waitForData.js
new file mode 100644
index 0000000..bf40c52
--- /dev/null
+++ b/util/waitForData.js
@@ -0,0 +1,9 @@
+module.exports = function waitForData(stream, cond = null) {
+  return new Promise(resolve => {
+    stream.on('data', data => {
+      if (cond ? cond(data) : true) {
+        resolve(data)
+      }
+    })
+  })
+}