Skip to content

Instantly share code, notes, and snippets.

@gpestana
Created June 29, 2014 18:03
Show Gist options
  • Save gpestana/c1c23980d0d3cd6d19d1 to your computer and use it in GitHub Desktop.
Save gpestana/c1c23980d0d3cd6d19d1 to your computer and use it in GitHub Desktop.
read of the day - node streams & event emitters
streams
streams can be seen as channels through were data flow in, out, or in both directions. the streams have different states, depending on what's happening at the given moment: streams can have data available, ready to receive more data, amongst others. these states are announced to the application through Events. thus, streams are EventEmitters which means they emit predefined events depending on its state. for example, when a source stream (from where data flows out) emits a 'readable' event, new data is ready to be read from that stream. the same happens with writtable streams and all the others. this design is really handy to control and monitor our streams and keeping the code clean and following a well defined design pattern.
streams are used in fs
in production code example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment