joyent/node — pull request #5865 by isaacs (2013-07-18 20:23:17+00:00)
Title: Streams3 - First Pass

This addresses #5860.

Performance-wise it seems to be on-par with master, and I haven't gone through and worked out any trouble spots with the V8 profiling tools.

The commits are a mess, and will be squashed of course, but the best way to see the high level view of what this enables is to check out . That test would switch a streams2 stream into old-mode, but with streams3, you hit `s.pause()` and it's right back where it was.

The other semantic change is that adding a `readable` event handler will not cause `readable` to be emitted until nextTick. Otherwise, stuff like this is problematic:

```javascript
function MyReadable() {
Readable.call(this);
this.on('readable', function() {
this.doSomeStuff();
});
}

var r = new MyReadable();
// never gets called! Already emitted in ctor
r.on('readable', function() {
r.read();
});
```

All other semantics should be identical to master. API should be identical.

Still todo: docs.

Review/feedback please: @jclulow @bnoordhuis @indutny @raynos @tjfontaine