Loading...
Loading...
Use only when the user explicitly requests migration from RxJava to Kotlin coroutines and/or flows.
npx skill4agent add rcosteira79/android-skills rxjava-migrationflatMapswitchMapSingleObservableSchedulerretryWhenzipcombineLatestFlowableSubjectretryWhenSingleObservable| RxJava | Coroutines/Flow |
|---|---|
| |
| |
| |
| ask — |
BehaviorSubjectStateFlow.valueSharedFlow(replay = 1).value.valueobserveOnSchedulers.io()Dispatchers.IOcomputation()DefaultmainThread()Mainsingle()newSingleThreadContext(...)newThread()IOobserveOn(AndroidSchedulers.mainThread())MainviewModelScopeMainsuspend funwithContextsubscribeOnwithContextsubscribeOnobserveOnflowOnmigration-map.mdretryWhenretryThrowable// WRONG — 'attempt' is a Throwable, not a Long; this does not compile
flow.retry(3) { attempt -> delay(attempt * 1000L); true }
// CORRECT — retry(n)'s predicate gets the cause
flow.retry(3) { cause -> cause is IOException }
// CORRECT — stateful backoff: attempt IS the 0-based index here
flow.retryWhen { cause, attempt ->
if (cause is IOException && attempt < 3) { delay((attempt + 1) * 1000L); true } else false
}retryWhen { cause, attempt -> }kotlinx-coroutines-rx3rx2observable.asFlow(); single.await(); maybe.awaitSingleOrNull(); completable.await() // Rx → coroutines
flow.asObservable(); flow.asSingle() // coroutines → Rx (asSingle throws if the flow emits 0 or 2+ elements)retryWhenSchedulerCoroutineDispatcherFlowablebufferconflateDROP_OLDESTflatMapswitchMapswitchMapflatMapLatestSubjectStateFlowSharedFlowonErrorResumeNextcatchcatch { e -> if (e is CancellationException) throw e else emit(fallback) }compositeDisposable.clear()onCleared()viewModelScope