Skip to content

Instantly share code, notes, and snippets.

@damien
Created January 5, 2011 07:21
Show Gist options
  • Select an option

  • Save damien/766021 to your computer and use it in GitHub Desktop.

Select an option

Save damien/766021 to your computer and use it in GitHub Desktop.
A quick test to mess around with em-synchrony.
source :rubygems
gem "eventmachine"
gem "em-synchrony", :require => "em-synchrony"
gem "em-http-request", :require => "em-http"
#!/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
}
@damien
Copy link
Author

damien commented Jan 5, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment