Created
August 27, 2017 06:57
-
-
Save kinnrot/b311d7abe490e3f751412571c95f9769 to your computer and use it in GitHub Desktop.
asynchronous awaited execution in event machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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