0

is it possible to send the same object to subscribers in Rx repeatedly? For exmaple this code(on Kotlin):

 val exmp = listOf("А")
        var observable = exmp.toObservable()
            observable.subscribeBy(
                    onNext = {
                        it + "1"
                        println(it)
                    },
                    onError = { it.printStackTrace() },
                    onComplete = { println("Done!") }
            )

I try to send string value "A" repeatedly to method onNext() and get "A111111". Method replay() of Rx library as I understand starting sending date again for new subsribers. In circle for date from observable not changing, just method is called several times

1 Answers1

0

You can try making your observable a ConnectableObservable doing observable.publish(); In this way all subscribers will get the same information and object will be created only once as well. https://github.com/ReactiveX/RxJava/wiki/Connectable-Observable-Operators

Zahid Rasheed
  • 1,536
  • 1
  • 10
  • 28