Thinking in EventEmitters

127 views
Skip to first unread message

Tom

unread,
Nov 2, 2012, 1:47:43 PM11/2/12
to nod...@googlegroups.com
Hello.

Wanting to start to use EventEmitters in my code I thought it would be a nice idea if I would abstract a Website class (that holds an express app and http server for now) so I can tell it to start and stop with events and know when it is done by receiving events.
The thing I'm not sure about is How to connect two EventEmitter instances, say a Website and a Logger or an Authenticator 'middleware' or something that routes HTTP requests by domain to Website objects, etc.

Does anyone have examples of code that I could look at?

Also, would it be possible, later, to separate parts out and have them emit their events over streams to each other in the network?

gr,

Tom

Tom

unread,
Nov 2, 2012, 2:37:38 PM11/2/12
to nod...@googlegroups.com

Tristan Slominski

unread,
Nov 3, 2012, 8:51:02 PM11/3/12
to nod...@googlegroups.com
It's sort of mean to have me look at generated code :D

The pattern that might work for you would be a shared event bus. Basically, create a single EventEmitter, and give it to all the pieces that you want to communicate with via events. One problem with it will be that you might need to namespace your events so that you can tell where they're coming from.
Reply all
Reply to author
Forward
0 new messages