lib/sinatra/cometio/client.rb in sinatra-cometio-0.4.0 vs lib/sinatra/cometio/client.rb in sinatra-cometio-0.4.1
- old
+ new
@@ -9,16 +9,18 @@
class Error < StandardError
end
include EventEmitter
attr_reader :url, :session
+ attr_accessor :timeout
def initialize(url)
raise ArgumentError, "invalid URL (#{url})" unless url.kind_of? String and url =~ /^https?:\/\/.+/
@url = url
@session = nil
@running = false
+ @timeout = 120
end
def push(type, data)
begin
res = HTTParty.post @url, :timeout => 10, :body => {:type => type, :data => data, :session => @session}
@@ -47,10 +49,10 @@
private
def get
Thread.new do
while @running do
begin
- res = HTTParty.get "#{@url}?session=#{@session}", :timeout => 120
+ res = HTTParty.get "#{@url}?session=#{@session}", :timeout => @timeout
unless res.code == 200
self.emit :error, "CometIO get error"
sleep 10
next
else