« get me outta code hell

waitForData.js « util - 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
blob: bf40c524c21fde5f57383d8d95b9e47b8b734788 (plain)
1
2
3
4
5
6
7
8
9
module.exports = function waitForData(stream, cond = null) {
  return new Promise(resolve => {
    stream.on('data', data => {
      if (cond ? cond(data) : true) {
        resolve(data)
      }
    })
  })
}