{"id":24926726,"url":"https://github.com/michaelwp/goSemaphore","last_synced_at":"2025-10-17T09:31:21.402Z","repository":{"id":245199551,"uuid":"817547175","full_name":"michaelwp/go-semaphore","owner":"michaelwp","description":"go-semaphore is a Go package that implements the semaphore pattern than can be used to manage the number of Goroutine to run concurrently.","archived":false,"fork":false,"pushed_at":"2024-06-23T09:03:27.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-26T13:28:48.274Z","etag":null,"topics":["concurrent","go","semaphore"],"latest_commit_sha":null,"homepage":"https://goblog.dev/articles/22","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/michaelwp.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":"2024-06-20T00:44:30.000Z","updated_at":"2024-07-02T14:03:02.000Z","dependencies_parsed_at":"2024-06-20T13:25:09.821Z","dependency_job_id":"5867099c-adf4-476e-9f25-cd9d25fb9a96","html_url":"https://github.com/michaelwp/go-semaphore","commit_stats":null,"previous_names":["michaelwp/go-semaphore"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Fgo-semaphore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Fgo-semaphore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Fgo-semaphore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelwp%2Fgo-semaphore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelwp","download_url":"https://codeload.github.com/michaelwp/go-semaphore/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236795226,"owners_count":19206006,"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":["concurrent","go","semaphore"],"created_at":"2025-02-02T12:53:13.246Z","updated_at":"2025-10-17T09:31:21.397Z","avatar_url":"https://github.com/michaelwp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-semaphore\ngo-semaphore is a Go package that implements the semaphore pattern than can be used to manage the number of Goroutine\nto run concurrently.\n\n### installation\n```shell\ngo get github.com/michaelwp/goSemaphore\n```\n\n### basic of use\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/michaelwp/goSemaphore\"\n\t\"sync\"\n\t\"time\"\n)\n\nfunc main() {\n\tsem := gosemaphore.SemaphoreNew(5) // \u003c-- set up the maximum allowed number of goroutine to run concurrently.\n\tvar wg sync.WaitGroup\n\n\tfor i := 0; i \u003c 50; i++ {\n\t\twg.Add(1)\n\n\t\tgo func(i int) {\n\t\t\tdefer wg.Done()\n\n\t\t\tsem.Acquire()       // \u003c-- to acquire a seat in buffered channel. This has to be at the beginning of the process.\n\t\t\tdefer sem.Release() // \u003c-- to release the seat. Strongly suggested to use defer to have a guarantee that this function will be executed when the process is finishes.\n\n\t\t\tlongRunningProcess(i)\n\t\t}(i)\n\t}\n\n\twg.Wait()\n}\n\nfunc longRunningProcess(taskID int) {\n\tfmt.Println(time.Now().Format(\"15:04:05\"), \"Running task with ID\", taskID)\n\ttime.Sleep(2 * time.Second)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelwp%2FgoSemaphore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelwp%2FgoSemaphore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelwp%2FgoSemaphore/lists"}