Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save International/206fd3fcbcd63c185fe6 to your computer and use it in GitHub Desktop.
Save International/206fd3fcbcd63c185fe6 to your computer and use it in GitHub Desktop.
async controller in rails with Thin, EventMachine, em-synchrony, em-http-request
class AsynctestController < ApplicationController
require "em-synchrony/em-http"
def test
EventMachine.synchrony do
http = EventMachine::HttpRequest.new("https://www.google.co.uk/").get
render :json => {result: http.response}
request.env['async.callback'].call(response)
end
throw :async
end
def test2
EventMachine.synchrony do
http = EventMachine::HttpRequest.new("https://www.google.co.uk/").get
render :json => {result: http.response}
request.env['async.callback'].call(response)
end
throw :async
end
end
gem 'thin'
gem 'em-http-request'
gem 'em-synchrony'
$.get("/asynctest/test");
$.get("/asynctest/test2");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment