Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally use setImmediate instead of nextTick in middleware #1081

Merged
merged 3 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/listener.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Listener
# Yes, we tried to execute the listener callback (middleware may
# have intercepted before actually executing though)
if cb?
process.nextTick -> cb true
Middleware.ticker -> cb true

response = new @robot.Response(@robot, message, match)
middleware.execute(
Expand Down
3 changes: 3 additions & 0 deletions src/middleware.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
async = require 'async'

class Middleware
# We use this recursively, and using nextTick recursively is deprecated in node 0.10.
@ticker: if typeof setImmediate is "function" then setImmediate else process.nextTick

constructor: (@robot) ->
@stack = []

Expand Down
2 changes: 1 addition & 1 deletion src/robot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class Robot
anyListenersExecuted = anyListenersExecuted || listenerExecuted
# Defer to the event loop at least after every listener so the
# stack doesn't get too big
process.nextTick () ->
Middleware.ticker () ->
# Stop processing when message.done == true
cb(context.response.message.done)
catch err
Expand Down