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.



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

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.



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

def thread
  @thread
end

#timeObject (readonly)

Returns the value of attribute time.



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

def time
  @time
end

Instance Method Details

#cancelObject

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



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

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

#raise(message) ⇒ Object

Raises if thread exists and alive.



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

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