{"id":26085247,"url":"https://github.com/modfin/kemu","last_synced_at":"2026-04-20T15:31:36.064Z","repository":{"id":281177487,"uuid":"944456992","full_name":"modfin/kemu","owner":"modfin","description":"Keyed mutex (lock map) for Go","archived":false,"fork":false,"pushed_at":"2025-03-07T11:37:45.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T09:52:15.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/modfin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2025-03-07T11:29:03.000Z","updated_at":"2025-03-07T11:37:19.000Z","dependencies_parsed_at":"2025-03-07T12:28:22.834Z","dependency_job_id":"1bd4433f-798b-4813-a53e-7c9897ab459c","html_url":"https://github.com/modfin/kemu","commit_stats":null,"previous_names":["modfin/kemu"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/modfin/kemu","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fkemu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fkemu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fkemu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fkemu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modfin","download_url":"https://codeload.github.com/modfin/kemu/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modfin%2Fkemu/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32053171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T11:35:06.609Z","status":"ssl_error","status_checked_at":"2026-04-20T11:34:48.899Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-03-09T05:57:57.858Z","updated_at":"2026-04-20T15:31:36.025Z","avatar_url":"https://github.com/modfin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kemu - Keyed Mutex for Go\n\n`kemu` is a simple, efficient implementation of a keyed mutex (lock map) for Go. It provides a way to lock operations based on string keys, allowing concurrent access to different keys while serializing access to the same key.\n\n## Features\n\n- Lock operations by string keys\n- Non-blocking TryLock operation\n- Clean memory management (no leaks from unused locks)\n- Thread-safe implementation\n- Simple, easy-to-use API\n\n## Installation\n\n```bash\ngo get github.com/modfin/kemu\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/modfin/kemu\"\n)\n\nfunc main() {\n    // Create a new keyed mutex\n    km := kemu.New()\n    \n    // Lock based on a key\n    key := \"user-123\"\n    km.Lock(key)\n    \n    // Critical section for this key\n    // ... perform operations that need exclusive access to this key ...\n    \n    // Unlock when done\n    km.Unlock(key)\n    \n    // Try to acquire a lock without blocking\n    if km.TryLock(key) {\n        // Lock acquired\n        // ... do something ...\n        km.Unlock(key)\n    } else {\n        // Lock not acquired, do something else\n        fmt.Println(\"Could not acquire lock for\", key)\n    }\n    \n    // Check if a key is currently locked\n    if km.Locked(key) {\n        fmt.Println(\"Key is locked\")\n    }\n}\n```\n\n## API Reference\n\n### `New() *Mutex`\n\nCreates a new keyed mutex instance.\n\n### `Lock(key string)`\n\nAcquires a lock for the specified key. If the key is already locked, this will block until the lock becomes available.\n\n### `TryLock(key string) bool`\n\nAttempts to acquire a lock for the specified key without blocking. Returns `true` if the lock was acquired, `false` otherwise.\n\n### `Unlock(key string)`\n\nReleases a lock for the specified key. Panics if the key is not locked.\n\n### `Locked(key string) bool`\n\nReturns `true` if the key is currently locked, `false` otherwise.\n\n## Implementation Details\n\n- The keyed mutex uses a map of string keys to lock entries\n- Each lock entry contains a mutex and a reference count\n- The implementation is not reentrant (the same goroutine cannot lock the same key multiple times)\n- Locks are automatically cleaned up when the last reference is released, preventing memory leaks\n\n## Concurrency Safety\n\n`kemu` is designed for high-concurrency environments and has been thoroughly tested with concurrent access patterns. It is safe to use from multiple goroutines simultaneously.\n\n## License\n\n[MIT License](LICENSE.md)\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodfin%2Fkemu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodfin%2Fkemu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodfin%2Fkemu/lists"}