Class: RxRuby::LocalScheduler
- Inherits:
-
Object
- Object
- RxRuby::LocalScheduler
- Includes:
- Scheduler
- Defined in:
- lib/rx_ruby/concurrency/local_scheduler.rb
Overview
Abstract base class for machine-local schedulers, using the local system clock for time-based operations.
Direct Known Subclasses
CurrentThreadScheduler, DefaultScheduler, ImmediateScheduler, ImmediateScheduler::AsyncLockScheduler
Instance Method Summary collapse
-
#now ⇒ Object
Gets the scheduler’s notion of current time.
-
#schedule_absolute_with_state(state, due_time, action) ⇒ Object
Schedules an action to be executed at dueTime.
- #schedule_relative_with_state(state, due_time, action) ⇒ Object
-
#schedule_with_state(state, action) ⇒ Object
Schedules an action to be executed.
Methods included from Scheduler
normalize, now, #schedule, #schedule_absolute, #schedule_recursive, #schedule_recursive_absolute, #schedule_recursive_absolute_with_state, #schedule_recursive_relative, #schedule_recursive_relative_with_state, #schedule_recursive_with_state, #schedule_relative
Instance Method Details
#now ⇒ Object
Gets the scheduler’s notion of current time.
12 13 14 |
# File 'lib/rx_ruby/concurrency/local_scheduler.rb', line 12 def now Time.now end |
#schedule_absolute_with_state(state, due_time, action) ⇒ Object
Schedules an action to be executed at dueTime.
24 25 26 27 28 |
# File 'lib/rx_ruby/concurrency/local_scheduler.rb', line 24 def schedule_absolute_with_state(state, due_time, action) raise 'action cannot be nil' unless action schedule_relative_with_state(state, (due_time - self.now), action) end |
#schedule_relative_with_state(state, due_time, action) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rx_ruby/concurrency/local_scheduler.rb', line 30 def schedule_relative_with_state(state, due_time, action) raise ArgumentError.new 'action cannot be nil' unless action dt = RxRuby::Scheduler.normalize due_time sleep dt if dt > 0 action.call(self, state) end |
#schedule_with_state(state, action) ⇒ Object
Schedules an action to be executed.
17 18 19 20 21 |
# File 'lib/rx_ruby/concurrency/local_scheduler.rb', line 17 def schedule_with_state(state, action) raise 'action cannot be nil' unless action schedule_relative_with_state(state, 0, action) end |