Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计通过

rxjava-to-coroutines-migrationrxjava 到协程的迁移

Agent Skill

用于辅助 Java 项目开发、面向对象设计、Spring 生态、Maven 或 Gradle 依赖和后端工程实践。它适合让 Agent 分析类结构、设计接口、整理服务分层、生成测试或检查常见代码坏味道。使用时需要结合项目已有架构、包结构和依赖版本,不应只按通用教程改代码;涉及数据库、事务、并发或框架配置时,应先确认运行环境和回归测试范围。

总安装

3,120

周安装

134

GitHub Stars

772

下载量

1,093
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:rxjava-to-coroutines-migration(rxjava 到协程的迁移)
来源仓库:https://github.com/new-silvermoon/awesome-android-agent-skills
仓库路径:skills/rxjava-to-coroutines-migration
安装命令:
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill rxjava-to-coroutines-migration
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill rxjava-to-coroutines-migration

简介

rxjava-to-coroutines-migration 用于辅助 Java 项目向协程迁移。

  • 它适合分析类结构、设计接口或整理服务分层,提升 Android 后端工程实践效率。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装,需结合原始 README 确认具体调用方式。
  • 使用时需结合项目已有架构和依赖版本,涉及数据库或并发时应确认回归测试范围。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

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

  1. Analyze the RxJava Chain: Identify the source type (Single, Observable, etc.), operators used, and where the subscription happens.
  2. 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.
  3. 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.
  4. 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).
  5. Handle Errors: Replace onError blocks with try/catch around suspend functions, or .catch {} operators on Flows.
  6. 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.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.75%
按下载量换算402

Claude

28.65%
按下载量换算313

Cursor

21%
按下载量换算230

Gemini CLI

10.53%
按下载量换算115

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills