Class: Reactive::Observable::Generate
- Defined in:
- lib/Reactive/observable/generate.rb
Instance Attribute Summary collapse
-
#continue_perdicate ⇒ Object
readonly
Returns the value of attribute continue_perdicate.
-
#init_value ⇒ Object
readonly
Returns the value of attribute init_value.
-
#inter_step_duration ⇒ Object
readonly
Returns the value of attribute inter_step_duration.
-
#result_projection ⇒ Object
readonly
Returns the value of attribute result_projection.
-
#step_action ⇒ Object
readonly
Returns the value of attribute step_action.
Instance Method Summary collapse
-
#initialize(init_value, continue_perdicate, step_action, result_projection, inter_step_duration) ⇒ Generate
constructor
A new instance of Generate.
- #run(observer) ⇒ Object
Methods inherited from Base
add_attributes, #first, #grep, #map, #maybe_scheduler, #merge, #observer_args, observer_on_next, #push, #scheduler, #skip, #subscribe, #subscribe_observer
Constructor Details
#initialize(init_value, continue_perdicate, step_action, result_projection, inter_step_duration) ⇒ Generate
Returns a new instance of Generate.
6 7 8 |
# File 'lib/Reactive/observable/generate.rb', line 6 def initialize(init_value, continue_perdicate, step_action, result_projection, inter_step_duration) @init_value, @continue_perdicate, @step_action, @result_projection, @inter_step_duration = init_value, continue_perdicate, step_action, result_projection, inter_step_duration end |
Instance Attribute Details
#continue_perdicate ⇒ Object (readonly)
Returns the value of attribute continue_perdicate.
4 5 6 |
# File 'lib/Reactive/observable/generate.rb', line 4 def continue_perdicate @continue_perdicate end |
#init_value ⇒ Object (readonly)
Returns the value of attribute init_value.
4 5 6 |
# File 'lib/Reactive/observable/generate.rb', line 4 def init_value @init_value end |
#inter_step_duration ⇒ Object (readonly)
Returns the value of attribute inter_step_duration.
4 5 6 |
# File 'lib/Reactive/observable/generate.rb', line 4 def inter_step_duration @inter_step_duration end |
#result_projection ⇒ Object (readonly)
Returns the value of attribute result_projection.
4 5 6 |
# File 'lib/Reactive/observable/generate.rb', line 4 def result_projection @result_projection end |
#step_action ⇒ Object (readonly)
Returns the value of attribute step_action.
4 5 6 |
# File 'lib/Reactive/observable/generate.rb', line 4 def step_action @step_action end |
Instance Method Details
#run(observer) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/Reactive/observable/generate.rb', line 10 def run(observer) is_first = true state = @init_value duration = @inter_step_duration action = @step_action projection = @result_projection continue = @continue_perdicate init_duration = duration.call(state) self.schedule_periodic(init_duration, lambda do if is_first is_first = false else state = action.call(state) end result = projection.call(state) observer.on_next(result) if continue.call(state) duration.call(state) else observer.on_complete() nil end end) end |