Module: RxRuby::PeriodicScheduler
- Included in:
- DefaultScheduler
- Defined in:
- lib/rx_ruby/concurrency/periodic_scheduler.rb
Overview
Provides periodic scheduling capabilities
Defined Under Namespace
Classes: PeriodicTimer
Instance Method Summary collapse
-
#schedule_periodic(period, action) ⇒ Object
Schedules a periodic piece of work by dynamically discovering the scheduler’s capabilities.
-
#schedule_periodic_with_state(state, due_time, action) ⇒ Object
Schedules a periodic piece of work.
Instance Method Details
#schedule_periodic(period, action) ⇒ Object
Schedules a periodic piece of work by dynamically discovering the scheduler’s capabilities.
9 10 11 12 13 14 15 16 17 |
# 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) ⇒ Object
Schedules a periodic piece of work
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |