Class: Rx::HotObservable

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/rx/testing/hot_observable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Observable

#_subscribe, #add_ref, #all?, #amb, amb, #and, #any?, #as_observable, #average, #buffer_with_count, #buffer_with_time, case, combine_latest, #combine_latest, #concat, concat, #concat_all, #concat_map, #concat_map_observer, #contains, #contains?, #count, create, #debounce, #default_if_empty, defer, #delay, #delay_with_selector, #dematerialize, #distinct, #distinct_until_changed, #do, #element_at, #element_at_or_default, empty, #empty?, #ensures, #enumerator_repeat_infinitely, #enumerator_repeat_times, #final, #first, #first_or_default, #flat_map, #flat_map_with_index, for, fork_join, from, from_array, generate, #group_join, if, #ignore_elements, interval, just, #last, #last_or_default, #latest, #map, #map_with_index, #materialize, #max, #max_by, #merge, #merge_all, merge_all, merge_concurrent, #merge_concurrent, #min, #min_by, #multicast, never, #none?, #observe_on, of, of_array, of_enumerable, of_enumerator, on_error_resume_next, #on_error_resume_next, pairs, #pluck, #publish, raise_error, range, #reduce, repeat, #repeat, repeat_infinitely, #repeat_infinitely, rescue_error, #rescue_error, #retry, #retry_infinitely, #scan, #select, #select_with_index, #sequence_eql?, #single, #single_or_default, #skip, #skip_last, #skip_until, #skip_while, #skip_while_with_index, start, #start_with, #subscribe_on, #subscribe_on_completed, #subscribe_on_error, #subscribe_on_next, #sum, #synchronize, #take, #take_last, #take_last_buffer, #take_until, #take_while, #take_while_with_index, #tap, #time_interval, timer, #timestamp, #to_a, to_async, #to_h, using, when, while, #window_with_count, #window_with_time, #zip, zip

Constructor Details

#initialize(scheduler, *args) ⇒ HotObservable

Returns a new instance of HotObservable.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rx/testing/hot_observable.rb', line 14

def initialize(scheduler, *args)
  raise 'scheduler cannot be nil' unless scheduler

  @scheduler = scheduler
  @messages = args
  @subscriptions = []
  @observers = []

  @messages.each do |message|
    notification = message.value
    @scheduler.schedule_at_relative_with_state(nil, message.time, lambda {|scheduler1, state1|

      @observers.clone.each {|observer| notification.accept observer }

      Subscription.empty
    })
  end
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



12
13
14
# File 'lib/rx/testing/hot_observable.rb', line 12

def messages
  @messages
end

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions.



12
13
14
# File 'lib/rx/testing/hot_observable.rb', line 12

def subscriptions
  @subscriptions
end

Instance Method Details

#subscribe(observer) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rx/testing/hot_observable.rb', line 33

def subscribe(observer)
  raise 'observer cannot be nil' unless observer

  @observers.push observer
  subscriptions.push (TestSubscription.new @scheduler.clock)

  index = subscriptions.length - 1

  Subscription.create do 
    @observers.delete observer
    subscriptions[index] = TestSubscription.new(subscriptions[index].subscribe, @scheduler.clock)
  end
end