Permalink
Browse files

Fix bug where next_tick'd blocks wouldn't run for sync actions.

  • Loading branch information...
1 parent 1052c19 commit 7bd1d01b98c7557978e1096cfa229ce90fdc5036 @phiggins committed Jun 15, 2011
Showing with 18 additions and 2 deletions.
  1. +8 −1 lib/thin/async/test.rb
  2. +10 −1 test/test_thin_async_test.rb
@@ -5,6 +5,7 @@ module Thin
module Async
class Test
VERSION = '1.0.0'
+
class Callback
attr_reader :status, :headers, :body
@@ -24,10 +25,16 @@ def initialize(app, options={})
def call(env)
callback = Callback.new
env.merge! 'async.callback' => callback
+
EM.run do
result = @app.call(env)
- return result unless result == Thin::AsyncResponse::Marker
+ EM.next_tick do
+ unless result == Thin::AsyncResponse::Marker
+ EM.stop
+ return result
+ end
+ end
end
[callback.status, callback.headers, callback.body]
@@ -14,7 +14,7 @@
response << BODY
- EM.add_timer(0.1) do
+ EM.next_tick do
response << BODY
response.done
@@ -46,4 +46,13 @@ def app
assert_equal "bar", last_response.headers["X-Foo"]
assert_equal BODY*2, last_response.body
end
+
+ it "doesn't hog the reactor's time" do
+ foo = nil
+ EM.next_tick { foo = "bar" }
+
+ get "/sync"
+
+ assert_equal "bar", foo
+ end
end

0 comments on commit 7bd1d01

Please sign in to comment.