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 |
That's a pretty good looking gem, good job.
I did this:
require 'angelo'
require 'http'
class ConcurrencyTestApp < Angelo::Base
get '/asynch_test' do
HTTP.get('http://localhost:5001/long_call', socket_class: Celluloid::IO::TCPSocket).response.body
end
end
ConcurrencyTestApp.run
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.
@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
hi, you left #celluloid before i could reply, but if rack is not a requirement, and you like sinatra, i was wondering if you could try my gem "angelo" ? (see github.com/kenichi/angelo) it's still pretty alpha and needs a lot of work but is potentially useful for you -
example:
then run: