Created
January 5, 2011 07:21
-
-
Save damien/766021 to your computer and use it in GitHub Desktop.
A quick test to mess around with em-synchrony.
This file contains hidden or 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
| source :rubygems | |
| gem "eventmachine" | |
| gem "em-synchrony", :require => "em-synchrony" | |
| gem "em-http-request", :require => "em-http" |
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require "rubygems" | |
| require "bundler" | |
| require "bundler/setup" | |
| require "json" | |
| require "em-synchrony" | |
| URL = "YOUR_SERVER/services/user/account" | |
| request = {} | |
| request[:body] = { | |
| "action" => "authenticateUser", | |
| "screenNameOrEmail" => "your_username", | |
| "password" => "super_secret_password" | |
| }.to_json | |
| require "em-http" | |
| EM.run { | |
| puts "EM start" | |
| http = EventMachine::HttpRequest.new(URL).post(request) | |
| http.callback { | |
| resp = JSON.parse http.response | |
| puts resp | |
| puts "EM Stop" | |
| EM.stop | |
| } | |
| puts "EM end of block" | |
| } | |
| require "em-synchrony/em-http" | |
| EventMachine.synchrony { | |
| puts "EM Sync start" | |
| http = EM::Synchrony.sync EventMachine::HttpRequest.new(URL).apost(request) | |
| puts JSON.parse http.response | |
| puts "EM Sync end of block" | |
| EM.stop | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When this example is run, we see "EM Stop" output before the result of the related request. The second request outputs "EM sync start" and related messages in the order which they appear in the code.