Closed chiefjester closed 9 years ago
I guess if you're not familiar with node's events
it isn't straight forward. barracks
is asynchronous by design.
// require barracks
const b = require('barracks')
// when 'beep' echo 'boop'
b.on('beep', () => console.log('boop'))
// wait 1 second, then call with value 'beep',
// triggering 'boop'
setTimeout(b.bind(null, 'beep'), 1000)
As displayed in the example: calling b('beep')
can be done in response to any async event. Does this asnwer your question?
ohh, now I get it it so like pub-sub?
Yup, exactly! Took me a while to realize that a router is actually a one-to-many relationship and an EventEmitter is the perfect abstraction for that.
thank you!, I'll be closing and experimenting on this.
Is there an example for this?