Class: Pitchfork::SoftTimeout::Request
- Inherits:
-
Object
- Object
- Pitchfork::SoftTimeout::Request
- Defined in:
- lib/pitchfork/soft_timeout.rb
Instance Attribute Summary collapse
-
#deadline ⇒ Object
readonly
Returns the value of attribute deadline.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #done? ⇒ Boolean
- #expired?(now) ⇒ Boolean
- #extend_deadline(timeout) ⇒ Object
- #finished ⇒ Object
-
#initialize(thread, timeout, block) ⇒ Request
constructor
A new instance of Request.
- #interrupt ⇒ Object
Constructor Details
#initialize(thread, timeout, block) ⇒ Request
Returns a new instance of Request.
18 19 20 21 22 23 24 25 |
# File 'lib/pitchfork/soft_timeout.rb', line 18 def initialize(thread, timeout, block) @thread = thread @deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout @block = block @mutex = Mutex.new @done = false # protected by @mutex end |
Instance Attribute Details
#deadline ⇒ Object (readonly)
Returns the value of attribute deadline.
16 17 18 |
# File 'lib/pitchfork/soft_timeout.rb', line 16 def deadline @deadline end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
16 17 18 |
# File 'lib/pitchfork/soft_timeout.rb', line 16 def thread @thread end |
Instance Method Details
#done? ⇒ Boolean
35 36 37 38 39 |
# File 'lib/pitchfork/soft_timeout.rb', line 35 def done? @mutex.synchronize do @done end end |
#expired?(now) ⇒ Boolean
41 42 43 |
# File 'lib/pitchfork/soft_timeout.rb', line 41 def expired?(now) now >= @deadline end |
#extend_deadline(timeout) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/pitchfork/soft_timeout.rb', line 27 def extend_deadline(timeout) @deadline += timeout QUEUE_MUTEX.synchronize do CONDVAR.signal end self end |
#finished ⇒ Object
57 58 59 60 61 |
# File 'lib/pitchfork/soft_timeout.rb', line 57 def finished @mutex.synchronize do @done = true end end |
#interrupt ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pitchfork/soft_timeout.rb', line 45 def interrupt @mutex.synchronize do unless @done begin @block.call(@thread) ensure @done = true end end end end |