{"id":13424697,"url":"https://github.com/discord/semaphore","last_synced_at":"2025-12-12T00:26:22.706Z","repository":{"id":40271007,"uuid":"82106195","full_name":"discord/semaphore","owner":"discord","description":"Fast semaphore using ETS.","archived":false,"fork":false,"pushed_at":"2024-06-07T09:10:33.000Z","size":13,"stargazers_count":750,"open_issues_count":4,"forks_count":48,"subscribers_count":191,"default_branch":"master","last_synced_at":"2025-04-04T01:09:26.950Z","etag":null,"topics":["elixir","erlang","locks","semaphore"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/discord.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":"2017-02-15T20:59:33.000Z","updated_at":"2025-03-24T11:54:38.000Z","dependencies_parsed_at":"2024-06-18T22:42:22.889Z","dependency_job_id":"4157854a-180d-46c2-b977-368780a8b2cf","html_url":"https://github.com/discord/semaphore","commit_stats":null,"previous_names":["discordapp/semaphore"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discord%2Fsemaphore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discord%2Fsemaphore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discord%2Fsemaphore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discord%2Fsemaphore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/discord","download_url":"https://codeload.github.com/discord/semaphore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248638096,"owners_count":21137602,"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":["elixir","erlang","locks","semaphore"],"created_at":"2024-07-31T00:00:58.032Z","updated_at":"2025-12-12T00:26:22.676Z","avatar_url":"https://github.com/discord.png","language":"Elixir","funding_links":[],"categories":["Elixir"],"sub_categories":[],"readme":"# Semaphore\n\n[![Master](https://travis-ci.org/discordapp/semaphore.svg?branch=master)](https://travis-ci.org/discordapp/semaphore)\n[![Hex.pm Version](http://img.shields.io/hexpm/v/semaphore.svg?style=flat)](https://hex.pm/packages/semaphore)\n\nProgramming in Erlang and Elixir usually allows for no locking since the VM essentially handles it for you when\ncommunicating between processes. However, what about the situation when you have thousands of processes attempting\nto interact with a single resource such as a process? Usually they will overload the process and explode the\nmessage queue. ETS is the Swiss Army knife of the Erlang VM and can be applied to this problem. By using `:ets.update_counter`\nand `:write_concurrency` we can achieve a **fast** low contention semaphore on ETS.\n\n## Usage\n\nAdd it to `mix.exs`\n\n```elixir\ndefp deps do\n  [{:semaphore, \"~\u003e 1.3\"}]\nend\n```\n\nThen just use it like a semaphore in any other language.\n\n```elixir\nif Semaphore.acquire(:test, 1) do\n  IO.puts \"acquired\"\n  Semaphore.release(:test)\nend\n\ncase Semaphore.call(:test, 1, fn -\u003e :ok end) do\n  :ok -\u003e\n    IO.puts \"success\"\n  {:error, :max} -\u003e\n    IO.puts \"too many callers\"\nend\n```\n\n## License\n\nSemaphore is released under [the MIT License](LICENSE).\nCheck [LICENSE](LICENSE) file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscord%2Fsemaphore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiscord%2Fsemaphore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscord%2Fsemaphore/lists"}