Skip to content

Instantly share code, notes, and snippets.

@JulienSansot
Last active January 16, 2016 00:08
Show Gist options
  • Save JulienSansot/8dc6c0f9f1d39706a629 to your computer and use it in GitHub Desktop.
Save JulienSansot/8dc6c0f9f1d39706a629 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