All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.noheltcj.rxcommon.subjects.BehaviorRelay.kt Maven / Gradle / Ivy

package com.noheltcj.rxcommon.subjects

import com.noheltcj.rxcommon.disposables.Disposable
import com.noheltcj.rxcommon.emitters.Emitter
import com.noheltcj.rxcommon.emitters.HotEmitter
import com.noheltcj.rxcommon.observers.Observer

open class BehaviorRelay(seed: E) : Subject() {
  override val emitter: Emitter = HotEmitter()

  var value = seed
    private set

  override fun subscribe(observer: Observer): Disposable {
    observer.onNext(value)
    return super.subscribe(observer)
  }

  override fun onNext(value: E) {
    this.value = value
    super.onNext(value)
  }

  /** This subject will not terminate */
  override fun onError(throwable: Throwable) {}

  /** This subject will not complete */
  override fun onComplete() {}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy