Module: EventMachine
- Defined in:
- lib/eventmachine/schedule_sync.rb
Class Method Summary collapse
-
.schedule_sync(&blk) ⇒ Object
Runs a block on the reactor thread and blocks the current thread while waiting for the result.
Class Method Details
.schedule_sync(&blk) ⇒ Object
Runs a block on the reactor thread and blocks the current thread while waiting for the result. If the block raises an exception, it will be re-thrown in the calling thread.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/eventmachine/schedule_sync.rb', line 11 def self.schedule_sync(&blk) promise = VCAP::Concurrency::Promise.new EM.schedule do begin if blk.arity > 0 blk.call(promise) else promise.deliver(blk.call) end rescue Exception => e promise.fail(e) end end promise.resolve end |