Creating a RX Observable without calling onComplete is it Valid?

from the CommonsWare Community archives

At March 29, 2020, 2:28pm, islam.farid2100 asked:

I am doing a polling operation which I have to wait for updates and I created Rx Observable for that; however, I never call onComplete. but in onDestroy I unsubscribe. please take a look on the below code.

    @Reusable
class TestPolling @Inject constructor() {
    var itemObservable: Observable<List<Items>>
        private set
    private lateinit var itemObservableEmitter: WeakReference<ObservableEmitter<List<Items>>>

    init {
        itemObservable = Observable.create { e -> itemObservableEmitter = WeakReference(e) }
    }

    fun submitData(items: List<Items>) {
        itemObservableEmitter.get()?.onNext(items)
    }
}

so is Valid to do something like that. I am not expert in Rx sorry if it is trivial question.


At March 29, 2020, 2:56pm, mmurphy replied:

I am not an RxJava expert, and so I have no idea whether your approach is considered to be a valid RxJava pattern or not. Sorry!