srough
v0.0.1
Published
Like `through` for async streams.
Downloads
3
Maintainers
Readme
srough
Like through for async streams.
In 90% of the cases you should use through.
Use srough
only when you're stream is async
.
The main idea is that streams are sync units that can perform async operations.
Data objects should be processed and written downstream in the same order they arrived from upstream.
Let's say we have a Transform stream that receives URL's from upstream and writes the response headers downstream.
Now, let's suppose that the urls are being written in the following order:
slowserver.com
fastserver.com
Downstream, should receive the response headers
in the same order exactly. If we'll use through
the URLs would be processed concurrently and the response would be written downstream in a random order.
Eventually, srough
is exactly the same thing as through, just with sync
callback.
Usage
var srough = require("srough");
var stream = srough(function write(data, done) {
somethingAsync(data, function (err, res) {
this.queue(res) //data *must* not be null
done(); // After you call this callback, will process next...
});
},
function end (done) { //optional
this.queue(null);
done();
});
Basically same API as through just with a synchronization callback.