An overview of buses
A bus is just like an EventStream, but it lets us push values into the stream manually instead of attaching it to a source, and it also allows plugging other EventStreams and properties into the bus on the fly.
Here is an example that demonstrates how to create a bus and various methods provided by a Bacon.Bus
instance. Place this code in the index.js
file:
var bus1 = new Bacon.Bus(); bus1.onValue(function(event){ console.log(event); }) bus1.push(1); bus1.push(2); var bus2 = new Bacon.Bus(); bus1.plug(bus2); bus2.push(3); bus1.error("Unknown Error"); //pushed an Bacon.Error bus1.end(); bus2.push(4); //this will not be pushed as bus has ended
The code is self explanatory. The output of the above code is as follows:
1 2 3