The problem I'm solving is controllability of the "when" interdependent
event emitters are connected and when they are disconnected. These are
meant purely as control structures.
For example, In order to connect multiple independent modules, I write code
that is something like the following:
var clientServer; // some event emitter
var peerServer; // some event emitter
var coordinator; // some event emitter
var peerClient; // some event emitter
var storage; // some event emitter
server.on('put', function (event, callback) {
coordinator.put(event, callback);
});
peerServer.on('_put', function (key, event, callback) {
storage._put(key, event, callback);
});
coordinator.on('_put', function (peer, key, event, callback) {
peerClient._put({hostname: peer.hostname}, key, event, callback);
});
This is not at all consumable. Also, given that all of the above event
emitters conform to specific APIs/interfaces, I can build different
implementations of them and "plug them in". The problem is that the
understanding of how all of these should be connected, like above, is not
straightforward to abstract.
What I hope to achieve with ControlRodAssembly abstraction, for example, is
to group the above configuration. I can do something like:
var app; // the application
app.controlAssembly = function (server, coordinator, peerServer, storage,
peerClient) {
var serverControlRod = new ControlRod(server, 'put', function (event,
callback) { coordinator.put(event, callback); });
var peerServerControlRod =
new ControlRod(peerServer, '_put', function (key, event, callback) {
storage._put(key, event, callback); });
var coordinatorControlRod =
new ControlRod(coordinator, '_put', function (peer, key, event,
callback) { peerClient._put(/*...*/); });
return new ControlRodAssembly(serverControlRod, peerServerControlRod,
coordinatorControlRod);
};
Now, app.controlAssembly contains the "wiring logic" of the application
that I can connect and disconnect at will via app.controlAssembly.connect()and
app.controlAssembly.disconnect().
This should give me control over sequencing of operations, so that I can
now initialize server, coordinator, etc... individually in whatever
sequence necessary, and when they are all ready to go, I can then call
app.controlAssembly.connect(). Again, the main effort here is on being able
to control when things happen.
On Monday, October 28, 2013 8:23:09 AM UTC-5, Tim Oxley wrote:
>
> I also think I'm re-inventing a pattern I should already know about.
>
>
> Streams probably.
>
> What do ControlRods / Assemblies provide over event emitters? What is the
> problem are you actually trying to solve? Perhaps update your code to show
> comparison between adding/removing listeners manually, and using your
> system.
>
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.