Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created August 14, 2011 06:18
Show Gist options
  • Save indexzero/1144639 to your computer and use it in GitHub Desktop.
Save indexzero/1144639 to your computer and use it in GitHub Desktop.
Request for Comments on EventEmitter2 and `.pipe()` APIs

Request for Comment

Implications for EventEmitter2 and .pipe() APIs

I have been working on refactoring node-cloudfiles to use @mikeal's request library for HTTPS uploads now that they are more stable. The current pull-request makes use of the continue event which it seems is not handled by the default .pipe() handler (for good reason). The work around potentially supporting this in request has made me revisit the need for EventEmitter2 with some new arguments that I find more compelling that those which were laid out before, that is: Selective Piping.

Selective Piping

Suppose that you wish to pipe arbitrary events from one stream to another, but only those which are relevant to your concerns. For example, if you were piping an http.ClientReqest stream to an http.ClientResponse stream you may wish to only pipe those events relevant to the http module (i.e. ignore those events from net.Stream).

If we were to use EventEmitter2, we could namespace these events under http:* and tcp:*. Clearly to put EventEmitter2 in these hot paths the wildcard implementation would need to be optimized for namespaces of length 2-3. Very infrequently do I find myself going deeper than foo:bar:baz.

I feel as though I'm really just scratching the surface here, and given the importance of the .pipe() API in the current road map (to my understanding anyway), I wanted to put it out there and see what the thoughts were from everyone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment