{"id":21462266,"url":"https://github.com/espoirx/optimusasynctask","last_synced_at":"2025-07-15T03:30:48.656Z","repository":{"id":145931182,"uuid":"229906618","full_name":"EspoirX/OptimusAsyncTask","owner":"EspoirX","description":"基于 kotlin Channel 的优先级异步任务队列","archived":false,"fork":false,"pushed_at":"2023-11-03T01:24:41.000Z","size":320,"stargazers_count":45,"open_issues_count":1,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T20:48:13.837Z","etag":null,"topics":["addtask","asynctask","blockingqueue","optimus","pai-dui","priorityblockingqueue","queue","runnow","task","taskpriority"],"latest_commit_sha":null,"homepage":"https://github.com/EspoirX/OptimusAsyncTask/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EspoirX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-12-24T08:50:38.000Z","updated_at":"2025-02-10T08:33:40.000Z","dependencies_parsed_at":"2023-04-16T00:18:57.918Z","dependency_job_id":"99297149-6e1b-4eb9-8cad-6ff5e94505fa","html_url":"https://github.com/EspoirX/OptimusAsyncTask","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/EspoirX/OptimusAsyncTask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EspoirX%2FOptimusAsyncTask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EspoirX%2FOptimusAsyncTask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EspoirX%2FOptimusAsyncTask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EspoirX%2FOptimusAsyncTask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EspoirX","download_url":"https://codeload.github.com/EspoirX/OptimusAsyncTask/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EspoirX%2FOptimusAsyncTask/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265397526,"owners_count":23758443,"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":["addtask","asynctask","blockingqueue","optimus","pai-dui","priorityblockingqueue","queue","runnow","task","taskpriority"],"created_at":"2024-11-23T07:13:22.111Z","updated_at":"2025-07-15T03:30:48.357Z","avatar_url":"https://github.com/EspoirX.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OptimusAsyncTask\n基于 kotlin Channel 的优先级异步任务队列\n\n适合于排队执行的任务实现，比如直播间动画排队播放。\n\n# 导入\n```gradle\nallprojects {\n  repositories {\n   ...\n   maven { url 'https://jitpack.io' }\n  }\n}\n\ndependencies {\n    implementation 'com.github.EspoirX:OptimusAsyncTask:v1.5'\n}\n```\n[![](https://jitpack.io/v/EspoirX/OptimusAsyncTask.svg)](https://jitpack.io/#EspoirX/OptimusAsyncTask)\n\n\n# 特点：\n1. 基于 kotlin Channel 实现\n2. 可设置优先级\n3. 使用简单\n\n\u003ca href=\"art/WechatIMG3.jpeg\"\u003e\u003cimg src=\"art/WechatIMG3.jpeg\" width=\"30%\"/\u003e\u003c/a\u003e\n\u003ca href=\"art/WechatIMG4.jpeg\"\u003e\u003cimg src=\"art/WechatIMG4.jpeg\" width=\"30%\"/\u003e\u003c/a\u003e\n\n# 介绍\nOptimusAsyncTask 将每个任务抽象成 OptimusTask，OptimusTask 可以设置任务执行时间，任务优先级，获取任务状态等。\n同时 OptimusAsyncTask 提供了 OptimusTask 的默认实现类 BaseOptimusTask，它实现了 Comparable 接口，任务按照优先级排序。\n\n**优先级 TaskPriority**\n 优先级的标准如下：\n TaskPriority.LOW \u003c TaskPriority.DEFAULT \u003c TaskPriority.HIGH\n 当优先级相同 按照插入次序排队\n 默认优先级是 TaskPriority.DEFAULT\n\n**任务**\n任务种类可分为 2 种，分别是 执行时间不确定 的任务和 执行时间确定 的任务。执行时间不确定的任务在任务执行完后需要调用\n doNextTask() 方法执行下一个任务，否则会一直挂起。\n执行时间确定的任务需要重写 getDuration() 方法返回具体的执行时间，单位是毫秒，执行时间到了会自动执行下一个任务。\n\n# 使用方法\n\n1. 创建执行时间不确定的任务\n```kotlin\nprivate class Task1(var textView: TextView) : OptimusTask() {\n\n    @SuppressLint(\"SetTextI18n\")\n    override fun doTask() {\n        textView.text = \"执行时间不确定的任务-\u003e \" + getSequence()\n\n        //模拟该任务耗时两秒\n        textView.postDelayed({\n            doNextTask() //执行下一个\n        }, 2000)\n    }\n\n    override fun finishTask() {\n        Log.i(\"Task1\", \"finishTask-\u003e \" + getSequence())\n    }\n}\n```\n2. 创建执行时间确定的任务\n```kotlin\nprivate class Task2(var textView: TextView) : OptimusTask() {\n\n    @SuppressLint(\"SetTextI18n\")\n    override fun doTask() {\n        textView.text = \"执行时间确定的任务-\u003e \" + getSequence()\n    }\n\n    //确定该任务耗时时间\n    override fun getDuration(): Long {\n        return 2000\n    }\n\n    override fun finishTask() {\n        Log.i(\"Task1\", \"finishTask-\u003e \" + getSequence())\n    }\n}\n```\n\n3. 通过任务管理器 OptimusTaskManager 开始执行任务\n\n一个 OptimusTaskManager 管理着一个任务队列。\n\n```kotlin\nval taskManager1 = OptimusTaskManager()\n\nval taskManager2 = OptimusTaskManager()\n```\n\n\n\n更多例子请查看 demo。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fespoirx%2Foptimusasynctask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fespoirx%2Foptimusasynctask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fespoirx%2Foptimusasynctask/lists"}