Class: LSync::EventTimer
- Inherits:
-
Object
- Object
- LSync::EventTimer
- Defined in:
- lib/lsync/event_timer.rb
Overview
The EventTimer provides a simple time based callback mechanism in which events can be aggregated. If the timer is triggered once, it will take at most max time for the callback to be triggered.
Instance Method Summary collapse
-
#initialize(max, &block) ⇒ EventTimer
constructor
Times are measured in seconds.
-
#join ⇒ Object
Wait for the timeout to complete nicely.
-
#trigger! ⇒ Object
Trigger the event timer such that within the specified time, the callback will be fired.
Constructor Details
#initialize(max, &block) ⇒ EventTimer
Times are measured in seconds. Min specifies the minimum duration between callback invocations. Max specifies the maximum duration between callback invocations.
36 37 38 39 40 41 42 43 44 |
# File 'lib/lsync/event_timer.rb', line 36 def initialize(max, &block) @max = max @fired = nil @timeout = nil @callback = Proc.new(&block) @processing = Mutex.new end |
Instance Method Details
#join ⇒ Object
Wait for the timeout to complete nicely.
73 74 75 76 77 |
# File 'lib/lsync/event_timer.rb', line 73 def join if @timeout @timeout.thread.join end end |