{"id":15675063,"url":"https://github.com/kikobeats/superlock","last_synced_at":"2026-05-24T12:02:46.465Z","repository":{"id":52443237,"uuid":"520828646","full_name":"Kikobeats/superlock","owner":"Kikobeats","description":"A mutex/semaphore implementation made easy to use.","archived":false,"fork":false,"pushed_at":"2024-11-19T19:28:33.000Z","size":94,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-09T00:06:03.154Z","etag":null,"topics":["mutex","mutex-lock","semaphore"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Kikobeats.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-08-03T10:06:34.000Z","updated_at":"2024-12-27T21:30:22.000Z","dependencies_parsed_at":"2024-02-09T00:24:15.948Z","dependency_job_id":"a89acd11-6b2e-407c-a8f3-f9afa94666d5","html_url":"https://github.com/Kikobeats/superlock","commit_stats":{"total_commits":58,"total_committers":3,"mean_commits":"19.333333333333332","dds":0.08620689655172409,"last_synced_commit":"3ef19ac0e6ad9fd9615f6dd4534e965c5efce8d0"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kikobeats%2Fsuperlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kikobeats%2Fsuperlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kikobeats%2Fsuperlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kikobeats%2Fsuperlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kikobeats","download_url":"https://codeload.github.com/Kikobeats/superlock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166518,"owners_count":21864476,"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":["mutex","mutex-lock","semaphore"],"created_at":"2024-10-03T15:55:38.564Z","updated_at":"2026-03-07T11:01:33.222Z","avatar_url":"https://github.com/Kikobeats.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Last version](https://img.shields.io/github/tag/Kikobeats/superlock.svg?style=flat-square)\n[![Coverage Status](https://img.shields.io/coveralls/github/Kikobeats/superlock?style=flat-square)](https://coveralls.io/github/Kikobeats/superlock)\n[![NPM Status](https://img.shields.io/npm/dm/superlock.svg?style=flat-square)](https://www.npmjs.org/package/superlock)\n\n\u003e A mutex/semaphore implementation made easy to use.\n\n## Why\n\n**superlock** aims to be:\n\n- **Simple**: Designed for usage with `async` and `await`\n- **Powerful**: Mutex \u0026 Semaphore patterns supported\n- **Secure**: Auto lock release toa void dead locks\n- **Lightweight**: No dependencies, just ~50 LOC\n- **Well-tested**: 100% code coverage\n\n## Install\n\n```bash\n$ npm install superlock --save\n```\n\n## Usage\n\n### as mutex\n\nThe lock is a mutex by default:\n\n```js\nconst { setTimeout } = require('timers/promises')\nconst { withLock } = require('superlock')\n\nconst lock = withLock()\n\nconst executions = await Promise.all(\n  [...Array(10).keys()].map(index =\u003e\n    lock(async () =\u003e {\n      await setTimeout(Math.random() * 100)\n      return index\n    })\n  )\n)\n\nconsole.log(executions)\n```\n\n### as semaphore\n\nJust call `withLock(n)` being `n` the maximum of concurrency desired for the lock.\n\n## API\n\n### withLock([concurrency=1])\n\nIt returns a function that can be used to wrap any code you want to execute with concurrency control:\n\n```js\nconst { withLock } = require('superlock')\n\nconst lock = withLock()\n\nawait lock(() =\u003e {\n  /* your code execution */\n})\n```\n\nThe lock will be automatically released after your code execution is done even if an error occurred, avoiding [deadlock](https://en.wikipedia.org/wiki/Deadlock) situations.\n\n#### concurrency\n\nType: `number`\u003cbr\u003e\nDefault: `1`\n\nIt sets the maximum of concurrency allowed for the lock.\n\n### .isLocked()\n\nType: `boolean`\n\nIt returns `false` if there is at least one free concurrency slots in the lock.\n\n## License\n\n**superlock** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/lock/blob/master/LICENSE.md) License.\u003cbr\u003e\nAuthored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/Kikobeats/lock/contributors).\n\n\u003e [kikobeats.com](https://kikobeats.com) · GitHub [Kiko Beats](https://github.com/Kikobeats) · X [@Kikobeats](https://x.com/Kikobeats)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkikobeats%2Fsuperlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkikobeats%2Fsuperlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkikobeats%2Fsuperlock/lists"}