Replaces timeout.rb to avoid Thread creation and scheduling overhead.
You should check another timeout replace in WEBrick. See lib/webrick/utils.rb in ruby/1.9.
About this implementation:
Do not create Thread for each timeout() call. Just create 1 Thread for timeout scheduler.
Do not wakeup the scheduler thread so often. Let scheduler thread sleep until the nearest period.
Creates new TimeoutScheduler.
# File lib/httpclient/timeout.rb, line 56 def initialize @pool = {} @next = nil @thread = start_timer_thread end
Cancels the given period.
# File lib/httpclient/timeout.rb, line 78 def cancel(period) @pool.delete(period) period.cancel end
Registers new timeout period.
# File lib/httpclient/timeout.rb, line 63 def register(thread, sec, ex) period = Period.new(thread, Time.now + sec, ex || ::Timeout::Error) @pool[period] = true if @next.nil? or period.time < @next begin @thread.wakeup rescue ThreadError # Thread may be dead by fork. @thread = start_timer_thread end end period end
Generated with the Darkfish Rdoc Generator 2.