Skip to content
Browse files

Use EventYoshi proxy instead of foreign emit.

Emitting an event on another emitter feels so wrong.
Use an EventYoshi proxy to call setAgentGroup on all
Agent objects used inside an AgentGroup.
  • Loading branch information...
1 parent 046e8ff commit 3de574cc00a48260194a2c7a32dae8cfedbb192b @reid reid committed Nov 7, 2012
Showing with 3 additions and 6 deletions.
  1. +3 −6 lib/hub/agent.js
View
9 lib/hub/agent.js
@@ -141,8 +141,6 @@ Agent.TTL = 45000;
Agent.prototype.setupEvents = function () {
var self = this;
- self.on("group", self.setAgentGroup.bind(self));
-
// Kickoff.
self.agentGroupEmitter.on("dispatch", self.next.bind(self));
@@ -374,10 +372,9 @@ function AgentGroup(manager, agents) {
this.useDirectURLs = false;
this.ttl = Agent.TTL;
- this.agentEmitter = new EventYoshi();
-
this.debug("Setup agentEmitter for", agents);
-
+ this.agentEmitter = new EventYoshi();
+ this.agentEmitter.proxy("setAgentGroup");
this.setupEvents();
this.appendAgents(agents);
@@ -402,7 +399,7 @@ AgentGroup.prototype.appendAgents = function (agents) {
agents.forEach(this.agentEmitter.add.bind(this.agentEmitter));
// Take ownership of all agents.
- this.agentEmitter.emit("group", this);
+ this.agentEmitter.setAgentGroup(this);
};
/**

0 comments on commit 3de574c

Please sign in to comment.
Something went wrong with that request. Please try again.