Skip to content

Instantly share code, notes, and snippets.

@kinnrot
Created August 27, 2017 06:57
asynchronous awaited execution in event machine
def execute_awaited
fiber = Fiber.current
execute # run some non blocking code (return immidiatly)
self.callback do |response|
EventMachine.schedule do
fiber.resume response
end
end
self.errback do |err|
EventMachine.schedule do
fiber.resume err
end
end
result = Fiber.yield
if result.is_a?(Exception)
raise result
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment