I'm very new to RxJava/RxAndroid and I'm very confused with how to achieve this workflow:
- Trigger void function
- Once it completes, provide some sort of callback to start a Completable function.
I tried wrapping my void function in an Observable that emits a , but honestly I've no clue if that's the right thing to do.
fun observableFoo(): Observable<Unit> {
return Observable.create<Unit> { emitter ->
emitter.onNext( voidFunction() )
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}
I have another completeable function inside which I have to subscribe to this Observable as follows:
fun onClick(): Completable {
observablefoo().subscribe {
Logger.e("demoApp", "inside subscribe - value = $it")
}
val x = someCompletableFunction()
return x
}
I want to be able to first wait for the subscription to finish and then trigger someCompletableFunction(). Is my approach even correct?
I've been stuck on this problem for a day and would really appreciate some help from anyone. Thank you.