{"id":24430664,"url":"https://github.com/dc0d/spool","last_synced_at":"2026-05-19T08:39:18.657Z","repository":{"id":42363591,"uuid":"365047127","full_name":"dc0d/spool","owner":"dc0d","description":"simple worker pool","archived":false,"fork":false,"pushed_at":"2022-11-01T22:00:29.000Z","size":30,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T14:57:25.228Z","etag":null,"topics":["go","golang","pool","worker-pool","workerpool","workers"],"latest_commit_sha":null,"homepage":"","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/dc0d.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":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2021-05-06T22:00:09.000Z","updated_at":"2021-10-10T10:52:04.000Z","dependencies_parsed_at":"2023-01-21T04:02:38.549Z","dependency_job_id":null,"html_url":"https://github.com/dc0d/spool","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dc0d%2Fspool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dc0d%2Fspool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dc0d%2Fspool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dc0d%2Fspool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dc0d","download_url":"https://codeload.github.com/dc0d/spool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243467025,"owners_count":20295309,"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":["go","golang","pool","worker-pool","workerpool","workers"],"created_at":"2025-01-20T14:57:27.210Z","updated_at":"2025-12-27T11:16:25.900Z","avatar_url":"https://github.com/dc0d.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spool\n\n[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](http://opensource.org/licenses/MIT)\n[![Go Reference](https://pkg.go.dev/badge/github.com/dc0d/spool.svg)](https://pkg.go.dev/github.com/dc0d/spool)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dc0d/spool)](https://goreportcard.com/report/github.com/dc0d/spool)\n\n\n**spool** is a simple worker-pool for Go. Each job is a `func()` which is sent to the worker-pool. A worker will pick up the job from the mailbox and execute it.\n\nFirst, initialize the worker-poll with a mailbox of a certain size:\n\n```go\npool := New(n)\ndefer pool.Stop()\n```\n\nThe mailbox is just a `chan func()`. In fact the worker-pool itself is defined as:\n\n```go\ntype WorkerPool chan func()\n```\n\nJobs can be sent to the worker-pool in two different manners, blocking and nonblocking. To send a job to the worker-pool and block until it's completed:\n\n```go\npool.Blocking(ctx, func() {\n    // ...\n})\n```\n\nAnd to send a job to the worker-pool and then move on:\n\n```go\npool.SemiBlocking(ctx, func() {\n    // ...\n})\n```\n\nAs long as there is an empty space in the mailbox, `SemiBlocking` will just queue the job, and moves on. When there are no more empty spaces in the mailbox, `SemiBlocking` becomes blocking.\n\nA worker-pool by default has no workers and they should be added explicitly. To add workers to the worker-pool:\n\n```go\npool.Grow(ctx, 10)\n```\n\nNow, the worker-pool has `10` workers.\n\nIt's possible to add temporary workers to the worker-pool:\n\n```go\npool.Grow(ctx, 9, WithAbsoluteTimeout(time.Minute * 5))\n```\n\nAlso, instead of using and absolute timeout, an idle timeout can be used. In this case, added workers will stop, if they are idle for a certain duration:\n\n```go\npool.Grow(ctx, 9, WithIdleTimeout(time.Minute * 5))\n```\n\nThe `Blocking` and `SemiBlocking` methods will panic if the worker-pool is stopped - to enforce visibility on job execution.\n\n## spool serializes the jobs in single worker mode\n\n- `TODO`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdc0d%2Fspool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdc0d%2Fspool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdc0d%2Fspool/lists"}