module RxRuby::PeriodicScheduler

Provides periodic scheduling capabilities

Public Instance Methods

schedule_periodic(period, action) click to toggle source

Schedules a periodic piece of work by dynamically discovering the scheduler’s capabilities.

# File lib/rx_ruby/concurrency/periodic_scheduler.rb, line 9
def schedule_periodic(period, action)
  raise 'action cannot be nil' unless action
  raise 'period cannot be less than zero' if period < 0

  self.schedule_periodic_with_state(action, period, lambda {|a|
    a.call
    return a
  })
end
schedule_periodic_with_state(state, due_time, action) click to toggle source

Schedules a periodic piece of work

# File lib/rx_ruby/concurrency/periodic_scheduler.rb, line 20
def schedule_periodic_with_state(state, due_time, action)
    raise 'action cannot be nil' unless action
    raise 'due_time cannot be less than zero' if due_time < 0

    state1 = state
    gate = Mutex.new

    PeriodicTimer.new due_time do 
      gate.synchronize do
        state1 = action.call state1
      end
    end
end