jerryhopper/skills/rxjava-to-coroutines-migration
Claude Code and agent skill by jerryhopper/skills
- community
Checking that the SKILL.md file is still in the repository.
Guide and execute the migration of asynchronous code from RxJava to Kotlin Coroutines and Flow. Use this skill when a user asks to convert RxJava (Observables, Singles, Completables, Subjects) to Coroutines (suspend functions, Flows, StateFlows).
Install
npx vskill@latest install jerryhopper/skills/rxjava-to-coroutines-migrationSKILL.md
The same SKILL.md was published earlier as moustachauve/wled-android/rxjava-to-coroutines-migration.
RxJava to Kotlin Coroutines Migration Skill
A specialized skill designed to safely and idiomatically refactor Android or Kotlin codebases from RxJava to Kotlin Coroutines and Flow.
Migration Mapping Guide
When migrating RxJava components to Kotlin Coroutines, use the following standard mappings:
1. Base Types
- `Single<T>` ->
suspend fun ...(): T - A single asynchronous value.
- `Maybe<T>` ->
suspend fun ...(): T? - A single asynchronous value that might not exist.
- `Completable` ->
suspend fun ...() - An asynchronous operation that completes without a value.
- `Observable<T>` ->
Flow<T> - A cold stream of values.
- `Flowable<T>` ->
Flow<T> - Coroutines Flow natively handles backpressure.
2. Subjects to Hot Flows
- `PublishSubject<T>` ->
MutableSharedFlow<T> - Broadcasts events to multiple subscribers. Use
MutableSharedFlow(extraBufferCapacity = ...)if buffering is needed. - `BehaviorSubject<T>` ->
MutableStateFlow<T> - Holds state and emits the current/latest value to new subscribers. Requires an initial value.
- `ReplaySubject<T>` ->
MutableSharedFlow<T>(replay = N) - Replays the last N emitted values to new subscribers.
3. Schedulers to Dispatchers
- `Schedulers.io()` ->
Dispatchers.IO - `Schedulers.computation()` ->
Dispatchers.Default - `AndroidSchedulers.mainThread()` ->
Dispatchers.Main - Context Switching:
subscribeOnandobserveOnare typically replaced bywithContext(Dispatcher)orflowOn(Dispatcher)for Flows.
4. Operators
- `map` ->
map - `filter` ->
filter - `flatMap` ->
flatMapMerge(concurrent) orflatMapConcat(sequential) - `switchMap` ->
flatMapLatest - `doOnNext` / `doOnSuccess` ->
onEach - `onErrorReturn` / `onErrorResumeNext` ->
catch { emit(...) } - `startWith` ->
onStart { emit(...) } - `combineLatest` ->
combine - `zip` ->
zip - `delay` ->
delay(suspend function) oronEach { delay(...) }
5. Execution and Lifecycle
- `subscribe()` ->
collect {}(for Flows) or direct invocation (for suspend functions) inside aCoroutineScope. - `Disposable.dispose()` ->
Job.cancel() - `CompositeDisposable.clear()` -> Cancel the parent
CoroutineScopeorJob.
Execution Steps
- Analyze the RxJava Chain: Identify the source type (Single, Observable, etc.), operators used, and where the subscription happens.
- Convert the Source: Change the return type in the repository or data source layer first. Convert to
suspendfunctions for one-shot operations, andFlowfor streams. - Rewrite Operators: Translate the RxJava operators to their Flow or Coroutine equivalents. Note that many RxJava operators can simply be replaced by standard Kotlin collection/sequence operations inside a
maporonEachblock. - Update the Subscription: Replace
.subscribe(...)withlaunch { ... }and.collect { ... }in the ViewModel or Presenter. Ensure the launch is tied to the correct lifecycle scope (e.g.,viewModelScope). - Handle Errors: Replace
onErrorblocks withtry/catcharound suspend functions, or.catch { }operators on Flows. - Handle Threading: Remove
.subscribeOn()and.observeOn(). UsewithContextwhere necessary, or.flowOn()to change the context of the upstream flow.
Example Transformation
RxJava:
Coroutines/Flow:
Best Practices
- Favor Suspend Functions: Default to
suspendfunctions instead ofFlowunless you actually have a stream of multiple values over time.SingleandCompletablealmost always becomesuspendfunctions. - State Handling: Use
StateFlowin ViewModels to expose state to the UI instead ofBehaviorSubjectorLiveData. - Lifecycle Awareness: Use
repeatOnLifecycleorflowWithLifecyclein the UI layer when collecting Flows to avoid background work when the view is not visible.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingandroid/migration/rxjava-to-coroutines-migration/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jerryhopper/skills/rxjava-to-coroutines-migration)