Module: VCAP::Spec::EM

Defined in:
lib/vcap/spec/em.rb

Instance Method Summary collapse

Instance Method Details

#doneObject



21
22
23
24
25
26
27
28
29
# File 'lib/vcap/spec/em.rb', line 21

def done
  raise "reactor not running" if !::EM.reactor_running?

  ::EM.next_tick {
    # Assert something to show a spec-pass
    :done.should == :done
    ::EM.stop_event_loop
  }
end

#em(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vcap/spec/em.rb', line 8

def em(options = {})
  raise "no block given" unless block_given?
  timeout = options[:timeout] ||= 1.0

  ::EM.run {
    quantum = 0.005
    ::EM.set_quantum(quantum * 1000) # Lowest possible timer resolution
    ::EM.set_heartbeat_interval(quantum) # Timeout connections asap
    ::EM.add_timer(timeout) { raise "timeout" }
    yield
  }
end