-
-
Save pentarex/263164f225f17db17aacdfc7cb52eccd to your computer and use it in GitHub Desktop.
Kotlin Observable.from is not waiting for observable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1st Try | |
Observable.zip<Unit, Long, Unit>(Observable.from(units), Observable.interval(5, TimeUnit.SECONDS)) { unit, t -> unit } | |
.subscribe({ unit -> | |
// execute bluetooth and wait for response with .onBackpressureBuffer() and .timeout in seconds | |
rxBluetoothService.sendAndReceiveWithTimeout("at+...", 10) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe({ response -> | |
// do some stuff here | |
}, { | |
//Handle error | |
}) | |
}) | |
//2nd Try | |
Observable.just(units) | |
.concatMap({unitsList -> Observable.from(unitsList)}) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribeOn(Schedulers.computation()) | |
.timeout(11, TimeUnit.SECONDS) | |
.flatMap({unit -> readBrakeValueFrom(unit, units, unitsMap).onErrorResumeNext(Observable.empty())}) | |
.subscribe() | |
private fun readValuesFromBt(command: String) : Observable<String>{ | |
return rxBluetoothService.sendAndReceiveWithTimeout("at+...", 10) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.doOnNext { btwiResponse -> | |
// same maging | |
} | |
.onErrorReturn({""}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment