class Rx::PeriodicScheduler::PeriodicTimer
Internal timer
Public Class Methods
new(seconds, &action)
click to toggle source
# File lib/rx/concurrency/periodic_scheduler.rb, line 38 def initialize(seconds, &action) @seconds = seconds @unsubscribed = false @gate = Mutex.new self.run_loop(&action) end
Public Instance Methods
run_loop() { || ... }
click to toggle source
# File lib/rx/concurrency/periodic_scheduler.rb, line 58 def run_loop Thread.new do should_run = true elapsed = 0 while should_run sleep @seconds - elapsed elapsed = time_block { yield } @gate.synchronize do should_run = !@unsubscribed end end end end
time_block() { || ... }
click to toggle source
# File lib/rx/concurrency/periodic_scheduler.rb, line 52 def time_block start_time = Time.new yield Time.new - start_time end
unsubscribe()
click to toggle source
# File lib/rx/concurrency/periodic_scheduler.rb, line 46 def unsubscribe @gate.synchronize do @unsubscribed = true unless @unsubscribed end end