{"id":18103749,"url":"https://github.com/azjezz/mutex","last_synced_at":"2026-01-20T02:32:07.712Z","repository":{"id":62490724,"uuid":"173337520","full_name":"azjezz/mutex","owner":"azjezz","description":"Mutex Locking for hack projects","archived":false,"fork":false,"pushed_at":"2020-06-18T23:06:40.000Z","size":7,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T11:32:53.802Z","etag":null,"topics":["hack","hacklang","hhvm","mutex","mutex-lock","mutual-exclusion"],"latest_commit_sha":null,"homepage":"","language":"Hack","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/azjezz.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}},"created_at":"2019-03-01T16:53:16.000Z","updated_at":"2019-03-02T15:36:43.000Z","dependencies_parsed_at":"2022-11-02T09:31:29.305Z","dependency_job_id":null,"html_url":"https://github.com/azjezz/mutex","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azjezz%2Fmutex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azjezz%2Fmutex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azjezz%2Fmutex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azjezz%2Fmutex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azjezz","download_url":"https://codeload.github.com/azjezz/mutex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441006,"owners_count":20939235,"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":["hack","hacklang","hhvm","mutex","mutex-lock","mutual-exclusion"],"created_at":"2024-10-31T22:13:04.056Z","updated_at":"2026-01-20T02:32:07.686Z","avatar_url":"https://github.com/azjezz.png","language":"Hack","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mutex\n\nHack implementation of [`reactphp-muxted`](https://github.com/WyriHaximus/reactphp-mutex) by [WyriHaximus](https://github.com/WyriHaximus).\n\n[![Build Status](https://travis-ci.org/azjezz/mutex.svg?branch=master)](https://travis-ci.com/azjezz/mutex)\n[![Latest Stable Version](https://poser.pugx.org/azjezz/mutex/v/stable.png?)](https://packagist.org/packages/azjezz/mutex)\n[![Total Downloads](https://poser.pugx.org/azjezz/mutex/downloads.png?)](https://packagist.org/packages/azjezz/mutex)\n[![License](https://poser.pugx.org/azjezz/mutex/license.png?)](https://packagist.org/packages/azjezz/mutex)\n\n---\n\n## Install\n\nTo install via Composer, use the command below :\n\n```console\ncomposer require azjezz/mutex\n```\n\n## About\n\nThis package provides two things:\n\n- An interface for [`mutex` locking](https://en.wikipedia.org/wiki/Mutual_exclusion)\n- A in-memory implementation of that interface\n\n## Example\n\n```hack\nuse namespace AzJezz\\Mutex;\nuse namespace HH\\Asio;\n\nrequire 'vendor/autoload.hack';\n\n\u003c\u003c__EntryPoint\u003e\u003e\nasync function main(): Awaitable\u003cvoid\u003e {\n  Facebook\\AutoloadMap\\initialize();\n\n  $mutex = new Mutex\\Memory();\n  \n  $jobs = vec[\n    foo($mutex), // first to acquire the lock\n    foo($mutex), // won't be able to acquire the lock\n    foo($mutex), // same\n  ];\n\n  foreach($jobs as $job) {\n    await $job;\n  }\n}\n\nasync function foo(\n  Mutex\\MutexInterface $mutex\n): Awaitable\u003cvoid\u003e {\n  $lock = await $mutex-\u003eacquire('foo');\n  if ($lock is nonnull) {\n    echo \"doing things \\n\";\n    await Asio\\usleep(10000000);\n    echo \"finished my job, releasing the lock \\n\";\n    await $mutex-\u003erelease($lock);\n    return;\n  }\n\n  echo \"someone else have requested the 'foo' lock\\n\";\n}\n\n```\n\n## License\n\nThe Mutex Project is open-sourced software licensed under the MIT-licensed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazjezz%2Fmutex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazjezz%2Fmutex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazjezz%2Fmutex/lists"}