fastest-writable v5.0.2
fastest-writable

Node.js Writable which goes at the speed of its fastest peer Writable and ends peers which can't keep up.
- Alternative to
readable.pipewhich goes at the rate of the slowest peer. - Peers which aren't drained when a write occurs are ended.
- With no peers added,
fastest-writableconsumes data as fast as it is written and throws it away. - Full set of unit tests with 100% coverage.
Example:
var stream = require('stream'),
assert = require('assert'),
FastestWritable = require('fastest-writable').FastestWritable,
source = new stream.PassThrough(),
fw = new FastestWritable(),
dest1 = new stream.PassThrough({ highWaterMark: 1 }),
dest2 = new stream.PassThrough({ highWaterMark: 1 });
source.pipe(fw);
fw.add_peer(dest1);
fw.add_peer(dest2);
source.write('foo');
assert.equal(dest1.read().toString(), 'foo');
source.write('bar');
// drain emitted next tick
process.nextTick(function ()
{
assert(dest2._writableState.ended);
});The API is described here.
Installation
npm install fastest-writableLicence
Test
grunt testCode Coverage
grunt coveragec8 results are available here.
Coveralls page is here.
Lint
grunt lintAPI
- FastestWritable
- FastestWritable.prototype.add_peer
- FastestWritable.prototype.remove_peer
- FastestWritable.events.empty
- FastestWritable.events.waiting
- FastestWritable.events.ready
- FastestWritable.events.laggard
- FastestWritable.events.peer_added
- FastestWritable.events.peer_removed
FastestWritable(options)
Creates a new
FastestWritableobject which can write to multiple peerstream.Writableobjects.
Inherits from stream.Writable so you can use any Writable method or event in addition to those described here.
Parameters:
{Object} [options]Configuration options. This is passed ontoWritable's constructor and can contain the following extra property:{Boolean} [end_peers_on_finish]Whether to callwritable.endon all peers when thisFastestWritableobject emits afinishevent. Defaults totrue.{Boolean} [destroy_peers_on_destroy]Whether to callwritable.destroyon all peers when thisFastestWritableis destroyed. Defaults totrue.{Boolean} [emit_laggard]Whether to emit an event namedlaggardon any peers which can't keep up instead of ending them. Defaults tofalse.
Go: TOC
FastestWritable.prototype.add_peer(peer)
Add a peer
Writableto the list of peers to which data will be written.
When writable.write is called on this FastestWritable object, the data is written to every peer. FastestWritable drains when at least one of its peers drains. When writable.write is called again, writable.end is called on any peer which hasn't drained from the previous writable.write call.
If this FastestWritable object has no peer Writables then it drains immediately.
Parameters:
{stream.Writable} peerPeerWritableto add.
Go: TOC | FastestWritable.prototype
FastestWritable.prototype.remove_peer(peer, end)
Remove a peer
Writablefrom the list of peers to which data will be written.
Parameters:
{stream.Writable} peerPeerWritableto remove.{Boolean} endWhether to callwritable.endon the peer once it's been removed from the list. Defaults totrue.
Go: TOC | FastestWritable.prototype
FastestWritable.events.empty()
emptyevent
A FastestWritable object emits an empty event when it has no more Writable objects in its list of peers.
Note that when a FastestWritable object is empty, it is always drained and throws any data it receives away.
You could, for example, end the FastestWritable object when empty is emitted.
Go: TOC | FastestWritable.events
FastestWritable.events.waiting(stop_waiting)
waitingevent
A FastestWritable object emits a waiting event when it's waiting for any of its peers to drain.
When a peer drains, the FastestWritable object will emit a ready event. If there are no listeners for the ready event then it will emit a drain event.
Parameters:
{Function} stop_waitingCall this function to force theFastestWritableobject to drain without waiting for any of its peers to drain. You could use this to implement a timeout, for example. It's safe to callstop_waitingmore than once or even after a peer has drained of its own accord.
Go: TOC | FastestWritable.events
FastestWritable.events.ready(num_waiting, total, drain)
readyevent
A FastestWritable object emits a ready event when one of its peers drains. It gives you the ability to control when the FastestWritable object emits drain.
Parameters:
{Integer} num_waitingNumber of peers which still haven't drained for the latest data written to theFastestWritableobject.{Integer} totalNumber of peers which received the latest data written to theFastestWritableobject.{Function} drainCall this function to let theFastestWritbleobject drain without waiting for any more of its peers to drain. It's safe to calldrainmore than once.
Go: TOC | FastestWritable.events
FastestWritable.events.laggard(peer)
laggardevent
A FastestWritable object emits a laggard event when one of its peers can't keep up, if emit_laggard was passed to the constructor. Note a laggard event is also emitted on the peer.
Parameters:
{stream.Writable} peerPeerWritablewhich can't keep up.
Go: TOC | FastestWritable.events
FastestWritable.events.peer_added(peer)
peer_addedevent
A FastestWritable object emits a peer_added event when a peer has been added to the list of peers to which data will be written.
Parameters:
{stream.Writable} peerPeer added.
Go: TOC | FastestWritable.events
FastestWritable.events.peer_removed(peer)
peer_removedevent
A FastestWritable object emits a peer_removed event when a peer has been removed from the list of peers to which data will be written.
Parameters:
{stream.Writable} peerPeer removed.
Go: TOC | FastestWritable.events
—generated by apidox—
2 years ago
3 years ago
3 years ago
3 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
7 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago