Class: Rx::ObserverBase

Inherits:
Object
  • Object
show all
Includes:
Observer
Defined in:
lib/rx/core/observer.rb

Overview

Base class for all Observer implementations

Instance Method Summary collapse

Methods included from Observer

allow_reentrancy, #as_observer, #checked, configure, create, from_notifier, #notify_on, prevent_reentrancy, #to_notifier

Constructor Details

#initialize(config) ⇒ ObserverBase

Returns a new instance of ObserverBase.



74
75
76
77
# File 'lib/rx/core/observer.rb', line 74

def initialize(config)
  @config = config
  @stopped = false
end

Instance Method Details

#disposeObject



84
85
86
# File 'lib/rx/core/observer.rb', line 84

def dispose
  unsubscribe
end

#fail(error) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/rx/core/observer.rb', line 110

def fail(error) 
  unless @stopped
    @stopped = true
    @config.on_error_action.call error
    return true
  end
  return false
end

#on_completedObject

Notifies the observer of the end of the sequence.



103
104
105
106
107
108
# File 'lib/rx/core/observer.rb', line 103

def on_completed
  unless @stopped
    @stopped = true
    @config.on_completed_action.call
  end
end

#on_error(error) ⇒ Object

Notifies the observer that an exception has occurred.



94
95
96
97
98
99
100
# File 'lib/rx/core/observer.rb', line 94

def on_error(error)
  raise 'Error cannot be nil' unless error
  unless @stopped
    @stopped = true
    @config.on_error_action.call error
  end
end

#on_next(value) ⇒ Object

Notifies the observer of a new element in the sequence.



89
90
91
# File 'lib/rx/core/observer.rb', line 89

def on_next(value)
  @config.on_next_action.call value unless @stopped
end

#unsubscribeObject

Unsubscribes from the current observer causing it to transition to the stopped state.



80
81
82
# File 'lib/rx/core/observer.rb', line 80

def unsubscribe
  @stopped = true
end