Skip to content

Commit

Permalink
Avoid listener to own class's event emitters
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Apr 16, 2011
1 parent c9f0639 commit b2de72f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
17 changes: 7 additions & 10 deletions lib/process.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions src/process.coffee
Expand Up @@ -89,9 +89,6 @@ exports.Process = class Process extends EventEmitter
else
raiseConfigError()

@on 'ready', ->
self._processConnections()

@on 'error', (error) ->
callback = self._activeConnection
self._activeConnection = null
Expand All @@ -101,10 +98,6 @@ exports.Process = class Process extends EventEmitter
else if self.listeners('error').length <= 1
throw error

# Push back the idle time everytime a request is handled
@on 'busy', ->
self.deferTimeout()

spawn: (callback) ->
return if @state

Expand Down Expand Up @@ -142,6 +135,7 @@ exports.Process = class Process extends EventEmitter
@heartbeat.on 'data', (data) =>
if "#{@child.pid}\n" is data.toString()
@changeState 'ready'
@_processConnections()
else
try
exception = JSON.parse data
Expand Down Expand Up @@ -229,16 +223,19 @@ exports.Process = class Process extends EventEmitter
@_activeConnection = @_connectionQueue.shift()

if @_activeConnection and @state is 'ready'
# Push back the idle time everytime a request is handled
@deferTimeout()

@changeState 'busy'

connection = client.createConnection @sockPath

@_activeConnection null, connection

connection.on 'close', ->
self._activeConnection = null
self.changeState 'ready'
self._processConnections()

@_activeConnection null, connection
else
@spawn()

Expand Down
2 changes: 1 addition & 1 deletion test/test_process.coffee
Expand Up @@ -103,7 +103,7 @@ exports.testCreateMultipleConnections = (test) ->
test.ifError err

openConnections++
client.on 'close', -> openConnections--
client.on 'end', -> openConnections--
test.same 1, openConnections

test.ok client
Expand Down

0 comments on commit b2de72f

Please sign in to comment.