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.
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
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
31 32 33 |
# File 'lib/httpclient/timeout.rb', line 31 def thread @thread end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
31 32 33 |
# File 'lib/httpclient/timeout.rb', line 31 def time @time end |
Instance Method Details
#cancel ⇒ Object
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() @lock.synchronize do if @thread and @thread.alive? @thread.raise(@ex, ) end end end |