Skip to content

Commit

Permalink
updated whenDone, onceDone to use wrapped callback
Browse files Browse the repository at this point in the history
  • Loading branch information
kksharma1618 committed Feb 1, 2015
1 parent 6a19a39 commit dd079a7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/taskgroup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ class Interface extends EventEmitter
whenDone: (listener) ->
# check if we have a listener
if typeof listener is 'function'
@on('done', listener.bind(@))
queuedListener = (args...) ->
process.nextTick () ->
listener(args...)

@on('done', queuedListener.bind(@))

# Chain
@
Expand All @@ -72,7 +76,11 @@ class Interface extends EventEmitter
onceDone: (listener) ->
# check if we have a listener
if typeof listener is 'function'
@once('done', listener)
queuedListener = (args...) ->
process.nextTick () ->
listener(args...)

@once('done', queuedListener)

# Chain
@
Expand Down Expand Up @@ -1280,4 +1288,4 @@ class TaskGroup extends Interface
@

# Export
module.exports = {Task,TaskGroup}
module.exports = {Task,TaskGroup}

0 comments on commit dd079a7

Please sign in to comment.