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 |
@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!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kenichi
That's a pretty good looking gem, good job.
I did this:
The long_call is running on a different server; so that we can test just as a client.
I execute the code
ruby angelo.rb
. Then I go to the browser and open two tabs to pointing to 'http://localhost:4567/asynch_test'. The first tab finished after 4 seconds. The second tab finishes after 8 seconds. So they are being handled sequentially.I am having the same issue pure Reel. Not sure what I should be doing.