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?
On Fri, Nov 2, 2012 at 6:47 PM, Tom <tom.wiel...@gmail.com> wrote:
> 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?
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.
> On Fri, Nov 2, 2012 at 6:47 PM, Tom <tom.w...@gmail.com <javascript:>>wrote:
>> 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?