Created
December 30, 2010 22:40
-
-
Save samstokes/760432 to your computer and use it in GitHub Desktop.
Example of using Deferrable to provide an asynchronous API to a synchronous method.
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 do_funky_stuff | |
d = EM::DefaultDeferrable.new | |
# do some long-running thing synchronously | |
d.succeed | |
return d | |
end | |
do_funky_stuff.callback { sleep 5; puts 'Done!' } # blocks for 5 seconds | |
# prints "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment