{"id":19749315,"url":"https://github.com/sipt/jelly","last_synced_at":"2026-06-09T03:41:47.742Z","repository":{"id":93174253,"uuid":"138981625","full_name":"sipt/jelly","owner":"sipt","description":"弹性channel池","archived":false,"fork":false,"pushed_at":"2018-06-29T05:21:28.000Z","size":64,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-10T21:21:26.335Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/sipt.png","metadata":{"files":{"readme":"README.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":"2018-06-28T07:22:09.000Z","updated_at":"2024-06-03T12:27:04.000Z","dependencies_parsed_at":"2023-07-15T20:00:14.231Z","dependency_job_id":null,"html_url":"https://github.com/sipt/jelly","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Fjelly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Fjelly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Fjelly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Fjelly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sipt","download_url":"https://codeload.github.com/sipt/jelly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241078983,"owners_count":19905967,"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":[],"created_at":"2024-11-12T02:26:01.524Z","updated_at":"2025-11-23T03:03:03.419Z","avatar_url":"https://github.com/sipt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jelly\n\n弹性channel池，用来接收数据并处理，当数据超出负载设置时扩容，当数据量减少时收缩。\n\n![channel pool](./static/channel_pool.png)\n\n- LoadFactor：负载系数，默认为3(容量右移位数，也可以理解为当前缓存数据到达缓存容量的87.5%时，为满载)\n\n- Selector：用于选择哪条channel来发送数据\n- Recv：后台不停调用，接收到值后调用处理函数`callback(v interface{})`\n- grow()：当`容量\u003c\u003c负载系数 \u003e 剩余空间`时，增加`option.Step`个channel来减轻当前channel的负载\n- shrink()：当收缩`option.Step`个channel后还不会达到满载时，就直接收\n\n**Example:**\n\n```go\nfunc main() {\n    var w sync.WaitGroup\n\tpool, err := NewChanPool(DefaultOption, func(v interface{}) {\n        //todo 处理v\n        fmt.Println(v)\n\t\tw.Done()\n\t})\n\tif err != nil {\n        panic(err)\n\t}\n\terr = pool.StartRecv()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n    w.Add(1000)\n\tfor i := 0; i \u003c 5; i++ {\n\t\tgo func() {\n\t\t\tfor i := 0; i \u003c 200; i++ {\n                pool.Send(i, true) // Send(值，是否允许阻塞)\n\t\t\t}\n\t\t}()\n\t}\n\tgo func() {\n\t\ttimer := time.NewTimer(5 * time.Second)\n\t\t\u003c-timer.C\n\t\tt.Fatal(\"time out\")\n\t}()\n\tw.Wait() //等待结束\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsipt%2Fjelly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsipt%2Fjelly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsipt%2Fjelly/lists"}