Module: EventMachine
- Extended by:
- EmStartStopTimeouts
- Defined in:
- lib/emrpc/console.rb,
lib/emrpc/util/safe_run.rb,
lib/emrpc/util/em_start_stop_timeouts.rb
Overview
This puts start_server, stop_server calls into the queue to ensure proper delays between them. TODO: make this thread-safe by adding mutex lock around access to @servers_m_queue
Defined Under Namespace
Modules: EmStartStopTimeouts
Class Method Summary collapse
- .run_in_thread(delay = 0.25, &blk) ⇒ Object
-
.safe_run(background = nil, &block) ⇒ Object
Allows to safely run EM in foreground or in a background regardless of is running already or not.
Methods included from EmStartStopTimeouts
queued_start_server, queued_stop_server
Class Method Details
.run_in_thread(delay = 0.25, &blk) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/emrpc/console.rb', line 6 def self.run_in_thread(delay = 0.25, &blk) blk = proc{} unless blk t = Thread.new do EventMachine.run(&blk) end sleep delay t end |
.safe_run(background = nil, &block) ⇒ Object
Allows to safely run EM in foreground or in a background regardless of is running already or not.
Foreground: EM::safe_run { … } Background: EM::safe_run(:bg) { … }
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/emrpc/util/safe_run.rb', line 7 def EventMachine::safe_run(background = nil, &block) if EventMachine::reactor_running? # Attention: here we loose the ability to catch # immediate connection errors. EventMachine::next_tick(&block) sleep if $em_reactor_thread && !background else if background $em_reactor_thread = Thread.new do EventMachine::run(&block) end else EventMachine::run(&block) end end end |