rxjava-to-coroutines-migration

Migrates RxJava Observables, Singles, and Subjects to Kotlin Coroutines and Flow.

948|94|Updated Feb 6, 2024
One-click install
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill rxjava-to-coroutines-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rxjava-to-coroutines-migration
Source: https://github.com/new-silvermoon/awesome-android-agent-skills/tree/main/.github/skills/migration/rxjava-to-coroutines-migration
Command: npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill rxjava-to-coroutines-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactoring an Android codebase from RxJava to Kotlin Coroutines is error-prone because every type, operator, scheduler, and subscription pattern has a different idiomatic equivalent. This Skill provides a complete mapping guide and a step-by-step execution process so the migration stays consistent and lifecycle-safe.

Core Features & Use Cases

  • Type Mapping: Converts Single, Maybe, Completable, Observable, and Flowable to suspend functions or Flow, and maps PublishSubject, BehaviorSubject, and ReplaySubject to SharedFlow or StateFlow.
  • Operator & Threading Translation: Replaces operators like flatMap, switchMap, and combineLatest with Flow equivalents, and swaps Schedulers for Dispatchers using withContext or flowOn.
  • Lifecycle-Safe Subscription Handling: Replaces Disposable and CompositeDisposable patterns with viewModelScope, Job cancellation, and repeatOnLifecycle collection.
  • Use Case: When a user asks to convert a repository returning Single<User> with subscribeOn/observeOn chains, the Skill rewrites it as a suspend function collected in viewModelScope with try/catch error handling.

Quick Start

Ask the agent to convert this RxJava repository class and its ViewModel subscription to Kotlin Coroutines and Flow.

Frequently Asked Questions about rxjava-to-coroutines-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert RxJava Single to Kotlin Coroutines?

Convert Single<T> to a suspend function returning T, and Completable to a suspend function returning Unit. Replace subscribeOn with withContext(Dispatchers.IO) inside the function and call it from a CoroutineScope like viewModelScope.

What is the Flow equivalent of BehaviorSubject in RxJava?

BehaviorSubject maps to MutableStateFlow, which holds the latest value and emits it to new collectors. Unlike BehaviorSubject, StateFlow requires an initial value and is the recommended way to expose state from ViewModels.

How do I replace subscribeOn and observeOn with Coroutines?

Replace Schedulers with Dispatchers: Schedulers.io() becomes Dispatchers.IO and AndroidSchedulers.mainThread() becomes Dispatchers.Main. Use withContext for suspend functions or flowOn to change the upstream context of a Flow.

Should I use Flow or suspend functions when migrating from RxJava?

Prefer suspend functions for one-shot operations like Single and Completable, and reserve Flow for actual streams of multiple values over time. This keeps the API simpler and avoids unnecessary stream machinery.

How do I handle RxJava CompositeDisposable in Coroutines?

Replace CompositeDisposable.clear() by cancelling the parent CoroutineScope or Job. Launching work in viewModelScope gives automatic cancellation when the ViewModel is cleared, removing the need for manual disposal.