rx-kotlin2

RxJava/RxKotlin: combineLatest that already completes if one source completes (not all)

泄露秘密 提交于 2019-12-25 04:19:20
问题 Basically, I have two Flowables F and G and I want to use combineLatest on them, but I want the combined Flowable to already complete if F completes (even if G is still running). Here is an example of what I what to achieve with an ugly solution: fun combineFandGbutTerminateIfFTerminates(F: Flowable<Int>, G: Flowable<Int>) : Flowable<Pair<Int, Int>> { val _F = F.share() val _G = G.takeUntil(_F.ignoreElements().toFlowable<Nothing>()) val FandG = Flowables.combineLatest(_F, _G) return FandG }

Using `onBackpressureLatest` to drop intermediate messages in blocking Flowable

你。 提交于 2019-12-25 00:26:31
问题 I have a chain where I do some blocking IO calls (e.g. HTTP-call). I want the blocking call to consume a value, proceed without interrupting, but drop everything that is piling up meanwhile, and then consume the next value in the same manner. Consider the following example: fun main() { Flowable.interval(100, TimeUnit.MILLISECONDS).onBackpressureLatest().map { Thread.sleep(1000) it }.blockingForEach { println(it) } } From a naive point of view, I would it expect to print something like 0, 10,

rxkotlin groupby is not working

你。 提交于 2019-12-13 03:41:41
问题 could you please help me to group by the following json and return a hashMap in kotlin based on date with RxKotlin? is so easy with just kotlin but really stuck for Rxkotlin. thanks val groupedTransactions = accountTransactions.transactions ?.groupBy { it.effectiveDate } "transactions": [{ "id": "44e5b2bc484331ea24afd85ecfb212c8", "effectiveDate": "20/07/2017", "description": "Kaching TFR from JOHN CITIZEN<br/>xmas donation", "amount": 12.00 }, { "id": "1506aeeb8c3a699b1e3c87db03156428",

RxJava: Combining hot and cold observable to wait for each other

只愿长相守 提交于 2019-12-08 03:39:57
问题 I have my observables defined like this val initLoading = Observable.fromCallable { println("${System.currentTimeMillis()}") } .subscribeOn(Schedulers.computation()) .delay(WAIT_TIME, TimeUnit.SECONDS) .map { "loading ${System.currentTimeMillis()}" } .observeOn(AndroidSchedulers.mainThread()) val click = RxView.clicks(button).map { "click ${System.currentTimeMillis()}" } initLoading.concatWith(click) .subscribeBy( onNext = { println("result $it") }, onError = { throw it } ) initialLoading