Skip to content

Instantly share code, notes, and snippets.

@samstokes
Created December 30, 2010 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samstokes/760432 to your computer and use it in GitHub Desktop.
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.
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