Skip to content

Commit

Permalink
Added test for reactor_thread? and fixed up EM.schedule for pre-react…
Browse files Browse the repository at this point in the history
…or schedules
  • Loading branch information
raggi committed Mar 29, 2009
1 parent 2db07fe commit 691fbfa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/eventmachine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def self.run blk=nil, tail=nil, &block
@threadpool = nil
end
@reactor_running = false
@reactor_thread = nil
end

until @tails.empty?
Expand Down Expand Up @@ -287,7 +288,7 @@ def self.reactor_thread?
# from the reactor thread. Accepts the same arguments as EM::Callback
def self.schedule(*a, &b)
cb = Callback(*a, &b)
if reactor_thread?
if reactor_running? && reactor_thread?
cb.call
else
next_tick { cb.call }
Expand Down
6 changes: 6 additions & 0 deletions tests/test_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ def test_byte_range_send
assert_equal($sent, $received)
end

def test_reactor_thread?
assert !EM.reactor_thread?
EM.run { assert EM.reactor_thread?; EM.stop }
assert !EM.reactor_thread?
end

def test_schedule_on_reactor_thread
x = false
EM.run do
Expand Down

0 comments on commit 691fbfa

Please sign in to comment.