Last active
August 29, 2015 13:58
-
-
Save Nerian/9942257 to your computer and use it in GitHub Desktop.
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 ConcurrencyTestApp < Sinatra::Base | |
get "/asynch_test" do | |
Net::HTTP.get(URI("http://localhost:5000/long_call")) | |
"Hello world" | |
end | |
get "/long_call" do | |
sleep 4 | |
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
get "/asynch_test" do | |
Celluloid.defer do | |
response = Net::HTTP.get(URI("http://localhost:5000/long_call")) | |
end | |
"Hello world" | |
end | |
Celluloid::Task::TerminatedError |
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
require 'sinatra' | |
require 'celluloid/io' | |
require 'http' | |
class HttpFetcher | |
include Celluloid::IO | |
def fetch(url) | |
HTTP.get(url, socket_class: Celluloid::IO::TCPSocket).response | |
end | |
end | |
class ConcurrencyTestApp < Sinatra::Base | |
get "/asynch_test" do | |
fetcher = HttpFetcher.new | |
response = fetcher.fetch('http://localhost:5001/long_call') | |
"Hello world" | |
end | |
# This is being run on another server | |
get "/long_call" do | |
sleep 4 | |
'woow' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Nerian, thanks! it's good to have use cases to test with! :)
So i tried this: https://gist.github.com/kenichi/9944480
and it seems to work... lemme know what you find!