
rxjava-to-coroutines-migration
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).
- Installs
- 331
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill rxjava-to-coroutines-migration- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads rxjava-to-coroutines-migration automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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.
- Broadcasts events to multiple subscribers. Use
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.IOSchedulers.computation()->Dispatchers.DefaultAndroidSchedulers.mainThread()->Dispatchers.Main- Context Switching:
subscribeOnandobserveOnare typically replaced bywithContext(Dispatcher)orflowOn(Dispatcher)for Flows.
4. Operators
map->mapfilter->filterflatMap->flatMapMerge(concurrent) orflatMapConcat(sequential)switchMap->flatMapLatestdoOnNext/doOnSuccess->onEachonErrorReturn/onErrorResumeNext->catch { emit(...) }startWith->onStart { emit(...) }combineLatest->combinezip->zipdelay->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 parentCoroutineScopeorJob.
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:
fun getUser(id: String): Single<User> { ... }
disposable.add(
getUser("123")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ user ->
view.showUser(user)
}, { error ->
view.showError(error)
})
)
Coroutines/Flow:
suspend fun getUser(id: String): User { ... } // Internally uses withContext(Dispatchers.IO) if needed
viewModelScope.launch {
try {
val user = getUser("123")
view.showUser(user)
} catch (e: Exception) {
view.showError(e)
}
}
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.
FAQ
What does the rxjava-to-coroutines-migration skill do?
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).
How do I install rxjava-to-coroutines-migration?
Run npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill rxjava-to-coroutines-migration in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/rxjava-to-coroutines-migration/ (personal) or .claude/skills/rxjava-to-coroutines-migration/ (project).
Which AI agents can use rxjava-to-coroutines-migration?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is rxjava-to-coroutines-migration safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains rxjava-to-coroutines-migration?
It is published by new-silvermoon in new-silvermoon/awesome-android-agent-skills. It has 331 recorded installs.
More from new-silvermoon/awesome-android-agent-skills
android-testing
new-silvermoon/awesome-android-agent-skills
Comprehensive testing strategy involving Unit, Integration, Hilt, and Screenshot tests.
gradle-build-performance
new-silvermoon/awesome-android-agent-skills
Debug and optimize Android/Gradle build performance. Use when builds are slow, investigating CI/CD performance, analyzing build scans, or identifying compilation bottlenecks.
compose-ui
new-silvermoon/awesome-android-agent-skills
Best practices for building UI with Jetpack Compose, focusing on state hoisting, detailed performance optimizations, and theming. Use this when writing or refactoring Composable functions.
android-gradle-logic
new-silvermoon/awesome-android-agent-skills
Expert guidance on setting up scalable Gradle build logic using Convention Plugins and Version Catalogs.
android-architecture
new-silvermoon/awesome-android-agent-skills
Expert guidance on setting up and maintaining a modern Android application architecture using Clean Architecture and Hilt. Use this when asked about project structure, module setup, or dependency injection.
kotlin-concurrency-expert
new-silvermoon/awesome-android-agent-skills
Kotlin Coroutines review and remediation for Android. Use when asked to review concurrency usage, fix coroutine-related bugs, improve thread safety, or resolve lifecycle issues in Kotlin/Android code.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.