The switch
stream multiplexes an readable stream across a series of writable streams.
All streams operate in object mode, meaning read and write events emit whole objects instead of buffers.
var sw = new Switch();
sw.case(Car).pipe( car_handler );
sw.case(Van).pipe( van_handler );
vehicles.pipe( sw ).pipe( misc_handler );
The Switch
stream is readable and writable.
The switch stream only emits events that are not captured by any of the case classes defined by switch.case( class )
.
+-------------+
+------> | stream 1 |
+----------+ +----------+ | +-------------+
| generate | | | |
| objects | ------> | switch | ---+------> +-------------+
+----------+ | | | | stream 2 |
+----------+ | +-------------+
|
+------> +-------------+
| stream 3 |
+-------------+