mcpbeat Sign in

Rxjava To Coroutines Migration Agent Skill

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).

1k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
910
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill rxjava-to-coroutines-migration

The instruction itself

10 sections, as written by the author

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*: subscribeOn and observeOn are typically replaced by withContext(Dispatcher) or flowOn(Dispatcher) for Flows.

4. Operators

  • map -> map
  • filter -> filter
  • flatMap -> flatMapMerge (concurrent) or flatMapConcat (sequential)
  • switchMap -> flatMapLatest
  • doOnNext / doOnSuccess -> onEach
  • onErrorReturn / onErrorResumeNext -> catch { emit(...) }
  • startWith -> onStart { emit(...) }
  • combineLatest -> combine
  • zip -> zip
  • delay -> delay (suspend function) or onEach { delay(...) }

5. Execution and Lifecycle

  • subscribe() -> collect {} (for Flows) or direct invocation (for suspend functions) inside a CoroutineScope.
  • Disposable.dispose() -> Job.cancel()
  • CompositeDisposable.clear() -> Cancel the parent CoroutineScope or Job.

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 suspend functions for one-shot operations, and Flow for 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 map or onEach block.
  • Update the Subscription: Replace .subscribe(...) with launch { ... } and .collect { ... } in the ViewModel or Presenter. Ensure the launch is tied to the correct lifecycle scope (e.g., viewModelScope).
  • Handle Errors: Replace onError blocks with try/catch around suspend functions, or .catch { } operators on Flows.
  • Handle Threading: Remove .subscribeOn() and .observeOn(). Use withContext where 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 suspend functions instead of Flow unless you actually have a stream of multiple values over time. Single and Completable almost always become suspend functions.
  • State Handling: Use StateFlow in ViewModels to expose state to the UI instead of BehaviorSubject or LiveData.
  • Lifecycle Awareness: Use repeatOnLifecycle or flowWithLifecycle in the UI layer when collecting Flows to avoid background work when the view is not visible.

Other skills for the same job

different authors, same section of the catalogue
MCP Builder
by anthropics
vendor ×13

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

30k tokens scripts
Changelog Generator
by frostant
×9

Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.

774 tokens
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
MCP Builder
by JayZeeDesign
×7

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

37k tokens scripts
Vercel React Native Skills
by vercel-labs
vendor ×6

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

39k tokens
Vercel React Best Practices
by ratacat
×5

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

34k tokens
Next Best Practices
by vercel-labs
vendor ×4

Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling

20k tokens
Using Git Worktrees
by ZhanlinCui
×4

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification

1k tokens

How to use it

Copy the folder

Take new-silvermoon/rxjava-to-coroutines-migration from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.