Class: HTTPClient::TimeoutScheduler::Period
- Inherits:
-
Object
- Object
- HTTPClient::TimeoutScheduler::Period
- Defined in:
- lib/httpclient/timeout.rb
Overview
Represents timeout period.
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancel this Period.
-
#initialize(thread, time, ex) ⇒ Period
constructor
Creates new Period.
-
#raise(message) ⇒ Object
Raises if thread exists and alive.
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
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
30 31 32 |
# File 'lib/httpclient/timeout.rb', line 30 def thread @thread end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
30 31 32 |
# File 'lib/httpclient/timeout.rb', line 30 def time @time end |
Instance Method Details
#cancel ⇒ Object
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() @lock.synchronize do if @thread and @thread.alive? @thread.raise(@ex, ) end end end |