Class: HTTPClient::TimeoutScheduler::Period

Inherits:
Object
  • Object
show all
Defined in:
lib/httpclient/timeout.rb

Overview

Represents timeout period.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread, time, ex) ⇒ Period

Creates new Period.



34
35
36
37
# File 'lib/httpclient/timeout.rb', line 34

def initialize(thread, time, ex)
  @thread, @time, @ex = thread, time, ex
  @lock = Mutex.new
end

Instance Attribute Details

#threadObject (readonly)

Returns the value of attribute thread.



31
32
33
# File 'lib/httpclient/timeout.rb', line 31

def thread
  @thread
end

#timeObject (readonly)

Returns the value of attribute time.



31
32
33
# File 'lib/httpclient/timeout.rb', line 31

def time
  @time
end

Instance Method Details

#cancelObject

Cancel this Period. Mutex is needed to avoid too-late exception.



49
50
51
52
53
# File 'lib/httpclient/timeout.rb', line 49

def cancel
  @lock.synchronize do
    @thread = nil
  end
end

#raise(message) ⇒ Object

Raises if thread exists and alive.



40
41
42
43
44
45
46
# File 'lib/httpclient/timeout.rb', line 40

def raise(message)
  @lock.synchronize do
    if @thread and @thread.alive?
      @thread.raise(@ex, message)
    end
  end
end