-
-
Save International/206fd3fcbcd63c185fe6 to your computer and use it in GitHub Desktop.
async controller in rails with Thin, EventMachine, em-synchrony, em-http-request
This file contains 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
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 |
This file contains 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
gem 'thin' | |
gem 'em-http-request' | |
gem 'em-synchrony' |
This file contains 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
$.get("/asynctest/test"); | |
$.get("/asynctest/test2"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment