{"id":19508132,"url":"https://github.com/wenlong-guo/coroutinebus","last_synced_at":"2026-05-15T06:37:58.099Z","repository":{"id":145267356,"uuid":"617508097","full_name":"Wenlong-Guo/CoroutineBus","owner":"Wenlong-Guo","description":"🚄🚄🚄Event Bus By Kotlin Coroutine.🚄🚄🚄用Kotlin协程制作的事件总线","archived":false,"fork":false,"pushed_at":"2023-04-13T15:23:00.000Z","size":4575,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-08T11:35:19.294Z","etag":null,"topics":["android","channel","coroutine","coroutine-bus","coroutinebus","flow","library","rxbus","rxbus2"],"latest_commit_sha":null,"homepage":"https://github.com/Wenlong-Guo/CoroutineBus","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Wenlong-Guo.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-22T14:35:50.000Z","updated_at":"2024-07-01T16:36:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"805738e8-c7bf-4fed-87d2-00880501d5d3","html_url":"https://github.com/Wenlong-Guo/CoroutineBus","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wenlong-Guo%2FCoroutineBus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wenlong-Guo%2FCoroutineBus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wenlong-Guo%2FCoroutineBus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wenlong-Guo%2FCoroutineBus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wenlong-Guo","download_url":"https://codeload.github.com/Wenlong-Guo/CoroutineBus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240761054,"owners_count":19853254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","channel","coroutine","coroutine-bus","coroutinebus","flow","library","rxbus","rxbus2"],"created_at":"2024-11-10T23:03:52.643Z","updated_at":"2026-05-15T06:37:58.070Z","avatar_url":"https://github.com/Wenlong-Guo.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CoroutineBus\n用Kotlin协程制作的事件总线框架.\n\n[![License](https://img.shields.io/badge/License-Apache--2.0-brightgreen.svg)](https://github.com/Wenlong-Guo/CoroutineBus/blob/master/license)\n![Api](https://img.shields.io/badge/API-14+-brightgreen.svg)\n![Release](https://img.shields.io/github/v/release/Wenlong-Guo/CoroutineBus?include_prereleases)\n\n## [English README](README.md)\n\n# 关于\n协程总线是基于 Kotlin 协程的事件总线。它是一种轻量级、高性能且易于使用的事件总线。它适用于Android，Java和Kotlin项目。\n\n# 下载示例代码安装包\n1. [点击此处下载](https://www.pgyer.com/CoroutineBus)\n2. 扫描下面二维码下载\n\n![download](release/QRcode.png)\n\n# 配置Gradle\n\n如果你的项目 Gradle 配置是在 `7.0 以下`，需要在 `build.gradle` 文件中加入\n```groovy\nallprojects {\n    repositories {\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n\n如果你的 Gradle 配置是 `7.0 及以上`，则需要在 `settings.gradle` 文件中加入\n```groovy\ndependencyResolutionManagement {\n    repositories {\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n\n在项目 app 模块下的 `build.gradle` 文件中加入远程依赖\n```groovy\ndependencies {\n    implementation 'com.github.Wenlong-Guo:CoroutineBus:2.0.0'\n}\n```\n\n# 用法\n\n1. 自动订阅\n```kotlin\nCoroutineBus.subscribeByLifecycle(\n    this, isSticky = false, replay = 1, lifecycleOwner = this\n) { event: RandomNumEvent -\u003e\n    // do something\n}\n```\n\n2. 发送事件\n```kotlin\nCoroutineBus.post(RandomNumEvent())\n```\n\n3. 取消订阅\n```kotlin\nCoroutineBus.unsubscribe(this, RandomNumEvent::class.java)\n```\n\n# API\n1. 自动订阅 自动取消订阅的 订阅功能\n```kotlin\n/**\n * 带LifecycleOwner的订阅事件\n *\n * @param id 订阅者的唯一标识\n * @param lifecycleOwner LifecycleOwner\n * @param isSticky 是否接收粘性事件(注意:如果[replay]为0 那么粘性事件将无法使用)\n * @param replay 缓存事件个数 默认缓存100个,如果为0 那么粘性事件将无法使用\n * @param dispatcher 指定协程的调度器\n * @param callback 回调函数\n */\ninline fun \u003creified T : Any\u003e CoroutineBus.subscribeByLifecycle(\n    id: Any,\n    lifecycleOwner: LifecycleOwner,\n    isSticky: Boolean = false,\n    replay: Int = 100,\n    dispatcher: CoroutineDispatcher = Dispatchers.Main,\n    noinline callback: suspend (event: T) -\u003e Unit\n) \n```\n\n2. 普通订阅\n```kotlin\n/**\n * 订阅事件\n *\n * @param id 订阅者的唯一标识\n * @param isSticky 是否接收粘性事件(注意:如果[replay]为0 那么粘性事件将无法使用)\n * @param replay 缓存事件个数.默认缓存100个.如果为0,那么粘性事件将无法使用\n * @param dispatcher 指定协程的调度器\n * @param callback 回调函数\n */\ninline fun \u003creified T : Any\u003e subscribe(\n    id: Any,\n    isSticky: Boolean = false,\n    replay: Int = 100,\n    dispatcher: CoroutineDispatcher,\n    noinline callback: suspend (event: T) -\u003e Unit\n)\n```\n\n3. 取消指定id的指定事件的订阅\n```kotlin\n/**\n * 取消该 [id] 的 [clazz] 事件的订阅\n *\n * @param id 订阅者的唯一标识\n * @param clazz 订阅的事件类型\n */\nfun \u003cT : Any\u003e unsubscribe(id: Any, clazz: Class\u003cT\u003e)\n```\n\n4. 取消订阅指定id的所有订阅\n```kotlin\n/**\n * 取消订阅该 [id] 的所有订阅\n *\n * @param id 订阅者的唯一标识\n */\nfun unsubscribe(id: Any) \n```\n\n5. 清理所有订阅者和该事件的数据源\n```kotlin\n/**\n * 清理所有订阅者和该事件的数据源\n *\n * @param clazz 订阅的事件类型\n */\nfun \u003cT : Any\u003e cleanEvent(clazz: Class\u003cT\u003e)\n```\n\n6. 是否已经注册过该事件\n```kotlin\n/**\n * 是否已经注册过该事件\n *\n *  @param id 订阅者的唯一标识\n *  @param clazz 订阅的事件类型\n */\nfun isSubscribed(id: Any, clazz: Class\u003c*\u003e): Boolean \n```\n\nLicense\n-------\n\n    Copyright 2023 Wenlong Guo\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwenlong-guo%2Fcoroutinebus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwenlong-guo%2Fcoroutinebus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwenlong-guo%2Fcoroutinebus/lists"}