module EventMachine::Synchrony

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 inlineCallbacks from Twisted (Python)
def self.sync(df)
  f = Fiber.current
  xback = proc do |*args|
    if f == Fiber.current
      return args.size == 1 ? args.first : args
    else
      f.resume(*args)
    end
  end
  df.callback(&xback)
  df.errback(&xback)
  Fiber.yield
end