Class: ServiceSkeleton::HurriableTimerSequence
- Inherits:
-
Object
- Object
- ServiceSkeleton::HurriableTimerSequence
- Defined in:
- lib/service_skeleton/hurriable_timer_sequence.rb
Overview
HurribleTimerSequence is a resettable version of HurriableTimer, designed for cases where some action needs to happen at at least some frequency, but may happen more often when other threads trigger the process early.
It would have been possible to implement this without requiring allocation on reset, by reusing the mutex and condition variable in the normal timer, but this version is more obviously correct.
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #hurry! ⇒ Object
-
#initialize(timeout) ⇒ HurriableTimerSequence
constructor
A new instance of HurriableTimerSequence.
- #reset! ⇒ Object
- #wait(t = nil) ⇒ Object
Constructor Details
#initialize(timeout) ⇒ HurriableTimerSequence
Returns a new instance of HurriableTimerSequence.
11 12 13 14 15 |
# File 'lib/service_skeleton/hurriable_timer_sequence.rb', line 11 def initialize(timeout) @mutex = Mutex.new @timeout = timeout @latest = ServiceSkeleton::HurriableTimer.new(@timeout) end |
Instance Method Details
#expired? ⇒ Boolean
32 33 34 |
# File 'lib/service_skeleton/hurriable_timer_sequence.rb', line 32 def expired? @mutex.synchronize { @latest }.expired? end |
#hurry! ⇒ Object
28 29 30 |
# File 'lib/service_skeleton/hurriable_timer_sequence.rb', line 28 def hurry! @mutex.synchronize { @latest }.hurry! end |
#reset! ⇒ Object
17 18 19 20 21 22 |
# File 'lib/service_skeleton/hurriable_timer_sequence.rb', line 17 def reset! @mutex.synchronize { @latest.hurry! @latest = ServiceSkeleton::HurriableTimer.new(@timeout) } end |
#wait(t = nil) ⇒ Object
24 25 26 |
# File 'lib/service_skeleton/hurriable_timer_sequence.rb', line 24 def wait(t = nil) @mutex.synchronize { @latest }.wait(t) end |