module EventMachine::Synchrony
def self.sleep( secs )
def self.sleep( secs ) fiber = Fiber.current EM::Timer.new(secs) { fiber.resume } Fiber.yield end
def self.sync(df)
Deferrable object, simply pass it to EM::Synchrony.sync
either succeeds or fails. You do not need to patch or modify the
yield and automatically resume your code (via Fibers) when the call
has a "callback" and an "errback", the sync methond will automatically
As long as the asynchronous function returns a Deferrable object, which
p result.response
result = EM::Synchrony.sync EventMachine::HttpRequest.new(URL).get
or callback-based methods under the hood. Example:
Synchrony.sync allows you to write sequential code while using asynchronous
sync is a close relative to inclineCallbacks from Twisted (Python)
def self.sync(df) f = Fiber.current df.callback { |r| f.resume(r) } df.errback { |r| f.resume(r) } Fiber.yield end