Class: EventMachine::Test

Inherits:
Module
  • Object
show all
Defined in:
lib/event_machine/test.rb

Defined Under Namespace

Classes: TimeoutError

Instance Method Summary collapse

Constructor Details

#initialize(timeout) ⇒ Test

Returns a new instance of Test.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/event_machine/test.rb', line 8

def initialize(timeout)
  super() do

    define_method(:em_test) do |&block|
      done_callback = -> { throw :stop }

      # Calling EM.stop does not work, since it waits for the timer to finish first.
      catch(:stop) do
        EventMachine.run do
          EventMachine.add_timer(timeout) { raise TimeoutError }
          block.call(done_callback)
        end
      end
    end

  end
end