4 ms·
So a readable stream is an EventEmitter, but it's not recommended that you actually listen for 'data' events? (Instead you're supposed to call read()?) That s
by mjs 14y ago
So a readable stream is an EventEmitter, but it's not recommended that you actually listen for 'data' events? (Instead you're supposed to call read()?) That seems ... counterintuitive.
Anyone know what you're supposed to do if you have code with multiple listeners for 'data' events?
- IsaacSchlueter 14y agoIf you add a listener for 'data', or call stream.resume() then it'll start flowing data as it receives it, just like v0.8 and before. The only caveat is that listening for 'end' will not automatically start the flow of data, so you do sometimes have to either call resume() or add a data listener. In practice, it's rare that you care about the end of the stream, but not about the data coming through it, except in tests. tl;dr Your existing programs will almost certainly Just Work.
- mjs 14y agoThanks. Is there any significant performance difference? (I'm wondering if it makes sense to roll my own "proxy" converting read()s to emit()s.)
- IsaacSchlueter 14y agoNo, it does not make sense to roll your own proxy turning read() calls into emits. You probably won't get it to go faster than it does now. Whether you use on('data') or read(), you get equivalent performance.