Class: Timeout::TimeoutRequest
- Inherits:
-
Object
- Object
- Timeout::TimeoutRequest
- Defined in:
- lib/rubysl/timeout/timeout.rb
Overview
Represents thr asking for it to be timeout at in secs seconds. At timeout, raise exc.
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#abort ⇒ Object
Abort this request, ie, we don’t care about tracking the thread anymore.
-
#cancel ⇒ Object
Raise @exception if @thread.
-
#elapsed(time) ⇒ Object
Called because
timeseconds have gone by. -
#initialize(secs, thr, exc) ⇒ TimeoutRequest
constructor
A new instance of TimeoutRequest.
Constructor Details
#initialize(secs, thr, exc) ⇒ TimeoutRequest
Returns a new instance of TimeoutRequest.
50 51 52 53 54 |
# File 'lib/rubysl/timeout/timeout.rb', line 50 def initialize(secs, thr, exc) @left = secs @thread = thr @exception = exc end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
56 57 58 |
# File 'lib/rubysl/timeout/timeout.rb', line 56 def left @left end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
56 57 58 |
# File 'lib/rubysl/timeout/timeout.rb', line 56 def thread @thread end |
Instance Method Details
#abort ⇒ Object
Abort this request, ie, we don’t care about tracking the thread anymore.
76 77 78 79 |
# File 'lib/rubysl/timeout/timeout.rb', line 76 def abort @thread = nil @left = 0 end |
#cancel ⇒ Object
Raise @exception if @thread.
66 67 68 69 70 71 72 |
# File 'lib/rubysl/timeout/timeout.rb', line 66 def cancel if @thread and @thread.alive? @thread.raise @exception, "execution expired" end @left = 0 end |
#elapsed(time) ⇒ Object
Called because time seconds have gone by. Returns true if the request has no more time left to run.
60 61 62 63 |
# File 'lib/rubysl/timeout/timeout.rb', line 60 def elapsed(time) @left -= time @left <= 0 end |