« get me outta code hell
1 2 3 4 5 6 7 8 9 10 11
export default function waitForData(stream, cond = null) { return new Promise(resolve => { const listener = data => { if (cond ? cond(data) : true) { resolve(data) stream.removeListener('data', listener) } } stream.on('data', listener) }) }