{"id":41336993,"url":"https://github.com/chalvern/gochan","last_synced_at":"2026-01-23T06:32:20.950Z","repository":{"id":45435425,"uuid":"189795100","full_name":"chalvern/gochan","owner":"chalvern","description":"pool of goroutine with buffer channel, for concurrent execution but events of individual object running sequentially","archived":false,"fork":false,"pushed_at":"2022-10-21T04:30:51.000Z","size":15,"stargazers_count":40,"open_issues_count":0,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-18T23:04:24.534Z","etag":null,"topics":["channel","golang","goroutine","thread-pool-executer"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chalvern.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}},"created_at":"2019-06-02T02:04:47.000Z","updated_at":"2023-11-17T09:14:15.000Z","dependencies_parsed_at":"2022-09-02T12:01:31.649Z","dependency_job_id":null,"html_url":"https://github.com/chalvern/gochan","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/chalvern/gochan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fgochan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fgochan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fgochan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fgochan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chalvern","download_url":"https://codeload.github.com/chalvern/gochan/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fgochan/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28682259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T05:48:07.525Z","status":"ssl_error","status_checked_at":"2026-01-23T05:48:07.129Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["channel","golang","goroutine","thread-pool-executer"],"created_at":"2026-01-23T06:32:20.441Z","updated_at":"2026-01-23T06:32:20.934Z","avatar_url":"https://github.com/chalvern.png","language":"Go","readme":"# Gochan\n\n## 背景\n一般情况下，我们可以通过定义一个带缓冲的 channel 变量接收某种事件，然后通过一个专用的 goroutine 消费执行这个 channel 中的事件。\n\n但是如果相关事件很多的时候，一个 goroutine 不够用了怎么办呢？或许我们会想到多创建几个专用的 goroutine 来并发地消费执行这个 channel 中的事件；如果 channel 中各个事件之间是独立的，是可行的，但是如果某些事件之间具有某种顺序上的约束，那么就需要对事件进行特定的分类。\n\n比如，一个订单的支付与货物发货，两个事件是需要保序的；但是不同的订单之间又是可以并发执行；其实就是实现一个微型的按特定主题分类的 pub-sub（发布-订阅）系统。以订单为例，可以根据订单单号，把相同单号的事件推送到同一个队列（channel），一个特定的执行器（goroutine）来消费执行这个队列中的事件，如此平行扩展多个类似的组合，实现并发。\n\n### 平常的设计\n\n通过定义一个带缓冲的 channel 变量接收某种事件，然后通过一个专用的 goroutine 消费执行这个 channel 中的事件。\n\n```bash\n\nevent -\u003e\n        |\nevent -\u003e buffer-channel -\u003e goroutine\n        |\nevent -\u003e\n\n```\n\n### 状态无依赖的并发设计\n\n事件之间完全没有状态依赖，因此可以简单扩展 goroutine 进行加快事件执行速度。\n\n```bash\n\nevent -\u003e                 -\u003egoroutine\n        |               |\nevent -\u003e buffer-channel -\u003e goroutine\n        |               |\nevent -\u003e                 -\u003egoroutine\n\n```\n\n### 状态存在依赖的并发设计\n\n引入一层分发器（dispatcher），根据某个特性（比如 uuid）把事件分发到相应的队列（buffer-channel）中。\n\n```bash\n\nevent -\u003e              -\u003e buffer-channel -\u003e goroutine\n        |            |\nevent --\u003e dispatcher -\u003e buffer-channel -\u003e goroutine\n        |            |\nevent -\u003e              -\u003e buffer-channel -\u003e goroutine\n\n```\n\n## 使用示例\n\n可以查看 [examples](./examples) 文件查看使用示例。\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalvern%2Fgochan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchalvern%2Fgochan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalvern%2Fgochan/lists"}