Skip to content

Instantly share code, notes, and snippets.

@Nerian
Last active August 29, 2015 13:58
Show Gist options
  • Save Nerian/9942257 to your computer and use it in GitHub Desktop.
Save Nerian/9942257 to your computer and use it in GitHub Desktop.
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
get "/asynch_test" do
Celluloid.defer do
response = Net::HTTP.get(URI("http://localhost:5000/long_call"))
end
"Hello world"
end
Celluloid::Task::TerminatedError
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
@kenichi
Copy link

kenichi commented Apr 2, 2014

@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