-
-
Notifications
You must be signed in to change notification settings - Fork 237
Closed
Labels
Description
Via a conversation in this issue (towards the bottom of my linked comment.)
I propose that we deprecate (with the intent of eliminating) the implicit flowing of streams via .on('data'), opting instead to encourage users to use .resume() and .pipe(). It breaks the EventEmitter API contract to have side-effects based on adding a listener, which surprises users. While there are ways around it for normal listeners (namely EventEmitter.prototype.on.call(stream, 'data', fn)), they're not natural, and EventEmitter APIs that call .on will still trigger side-effect-ful behavior (for example, .once).
Benefits
- Streams would only have two states, flowing and paused, instead of the three they have currently (the undocumented third state, "undefined").
- Streams may be
.pause()'d and.resume()'d without losing access to the third "undefined" state.
Obstacles
Readable#pipecould no longer rely on the implicit flowing behavior of.on('data')to start the stream (so we would likely have to callsrc.resume()).streams1.Stream#pipeis entirely separate from `Readable#pipe. This may or may not prove to be a problem since streams1 streams implicitly flowed to begin with.- Messaging/education – we don't want people to get streamsN fatigue.
- In general in io.js/node development, it's hard to tell how many packages will break due to a given change, or even to get a read on the number of users of a given feature.
Questions
- Is the simplification of the streams state machine worth the effort (for us as well as for end users)?
- In general, is making the API more explicit desirable? If so, what would it look like if
.resume()was the only method to start flowing a stream? I.E., if this class of change represents "a good thing," why not take it even further?
/cc @iojs/streams