Module: RxRuby::Scheduler
- Included in:
- LocalScheduler, VirtualTimeScheduler
- Defined in:
- lib/rx_ruby/concurrency/scheduler.rb
Overview
Module for scheduling actions
Class Method Summary collapse
-
.normalize(time_span) ⇒ Object
Normalizes the specified TimeSpan value to a positive value.
-
.now ⇒ Object
Gets the current time according to the local machine’s system clock.
Instance Method Summary collapse
-
#schedule(action) ⇒ Object
Schedules an action to be executed.
-
#schedule_absolute(due_time, action) ⇒ Object
Schedules an action to be executed at the specified absolute due time.
-
#schedule_recursive(action) ⇒ Object
Schedules an action to be executed recursively.
-
#schedule_recursive_absolute(due_time, action) ⇒ Object
Schedules an action to be executed recursively after a specified absolute due time.
-
#schedule_recursive_absolute_with_state(state, due_time, action) ⇒ Object
Schedules an action to be executed recursively after a specified absolute due time.
-
#schedule_recursive_relative(due_time, action) ⇒ Object
Schedules an action to be executed recursively after a specified relative due time.
-
#schedule_recursive_relative_with_state(state, due_time, action) ⇒ Object
Schedules an action to be executed recursively after a specified relative due time.
-
#schedule_recursive_with_state(state, action) ⇒ Object
Schedules an action to be executed recursively.
-
#schedule_relative(due_time, action) ⇒ Object
Schedules an action to be executed after the specified relative due time.
Class Method Details
.normalize(time_span) ⇒ Object
Normalizes the specified TimeSpan value to a positive value.
78 79 80 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 78 def self.normalize(time_span) time_span < 0 ? 0 : time_span end |
.now ⇒ Object
Gets the current time according to the local machine’s system clock.
11 12 13 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 11 def self.now Time.now end |
Instance Method Details
#schedule(action) ⇒ Object
Schedules an action to be executed.
16 17 18 19 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 16 def schedule(action) raise 'action cannot be nil' unless action schedule_with_state(action, method(:invoke)) end |
#schedule_absolute(due_time, action) ⇒ Object
Schedules an action to be executed at the specified absolute due time.
28 29 30 31 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 28 def schedule_absolute(due_time, action) raise 'action cannot be nil' unless action schedule_absolute_with_state(action, due_time, method(:invoke)) end |
#schedule_recursive(action) ⇒ Object
Schedules an action to be executed recursively.
34 35 36 37 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 34 def schedule_recursive(action) raise 'action cannot be nil' unless action schedule_recursive_with_state(action, lambda {|_action, _self| _action.call(lambda { _self.call(_action) }) }) end |
#schedule_recursive_absolute(due_time, action) ⇒ Object
Schedules an action to be executed recursively after a specified absolute due time.
62 63 64 65 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 62 def schedule_recursive_absolute(due_time, action) raise 'action cannot be nil' unless action schedule_recursive_absolute_with_state(action, due_time, lambda {|_action, _self| _action.call(lambda {|dt| _self.call(_action, dt) }) }) end |
#schedule_recursive_absolute_with_state(state, due_time, action) ⇒ Object
Schedules an action to be executed recursively after a specified absolute due time.
68 69 70 71 72 73 74 75 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 68 def schedule_recursive_absolute_with_state(state, due_time, action) raise 'action cannot be nil' unless action schedule_absolute_with_state( { :state => state, :action => action}, due_time, lambda { |sched, pair| invoke_recursive_time(sched, pair, 'schedule_absolute_with_state') } ) end |
#schedule_recursive_relative(due_time, action) ⇒ Object
Schedules an action to be executed recursively after a specified relative due time.
46 47 48 49 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 46 def schedule_recursive_relative(due_time, action) raise 'action cannot be nil' unless action schedule_recursive_relative_with_state(action, due_time, lambda {|_action, _self| _action.call(lambda {|dt| _self.call(_action, dt) }) }) end |
#schedule_recursive_relative_with_state(state, due_time, action) ⇒ Object
Schedules an action to be executed recursively after a specified relative due time.
52 53 54 55 56 57 58 59 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 52 def schedule_recursive_relative_with_state(state, due_time, action) raise 'action cannot be nil' unless action schedule_relative_with_state( { :state => state, :action => action}, due_time, lambda { |sched, pair| invoke_recursive_time(sched, pair, 'schedule_relative_with_state') } ) end |
#schedule_recursive_with_state(state, action) ⇒ Object
Schedules an action to be executed recursively.
40 41 42 43 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 40 def schedule_recursive_with_state(state, action) raise 'action cannot be nil' unless action schedule_with_state({ :state => state, :action => action}, method(:invoke_recursive)) end |
#schedule_relative(due_time, action) ⇒ Object
Schedules an action to be executed after the specified relative due time.
22 23 24 25 |
# File 'lib/rx_ruby/concurrency/scheduler.rb', line 22 def schedule_relative(due_time, action) raise 'action cannot be nil' unless action schedule_relative_with_state(action, due_time, method(:invoke)) end |