{"id":15646448,"url":"https://github.com/martinheidegger/flexlock","last_synced_at":"2025-07-23T17:05:03.933Z","repository":{"id":57238321,"uuid":"120326898","full_name":"martinheidegger/flexlock","owner":"martinheidegger","description":"A memory-efficient, in-memory, flexible, Promise-based locking library without dependencies.","archived":false,"fork":false,"pushed_at":"2019-04-26T04:14:00.000Z","size":178,"stargazers_count":6,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T04:34:02.857Z","etag":null,"topics":["javascript","lock","multithreading","mutex","mutex-lock","mutex-synchronisation","process"],"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/martinheidegger.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-05T15:58:04.000Z","updated_at":"2024-11-21T10:35:40.000Z","dependencies_parsed_at":"2022-08-26T14:13:01.035Z","dependency_job_id":null,"html_url":"https://github.com/martinheidegger/flexlock","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fflexlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fflexlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fflexlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fflexlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinheidegger","download_url":"https://codeload.github.com/martinheidegger/flexlock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251700976,"owners_count":21629848,"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":["javascript","lock","multithreading","mutex","mutex-lock","mutex-synchronisation","process"],"created_at":"2024-10-03T12:12:57.476Z","updated_at":"2025-04-30T12:23:20.916Z","avatar_url":"https://github.com/martinheidegger.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flexlock\n\n\n\u003ca href=\"https://travis-ci.org/martinheidegger/flexlock\"\u003e\u003cimg src=\"https://travis-ci.org/martinheidegger/flexlock.svg?branch=master\" alt=\"Build Status\"/\u003e\u003c/a\u003e\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Maintainability](https://api.codeclimate.com/v1/badges/64b42212bd9ebab25cda/maintainability)](https://codeclimate.com/github/martinheidegger/flexlock/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/64b42212bd9ebab25cda/test_coverage)](https://codeclimate.com/github/martinheidegger/flexlock/test_coverage)\n\n`flexlock` is a **small**, **memory-concious**, **flexible**, **Promise**-based locking library without dependencies.\n\n`npm i flexlock --save`\n\nIt is similar to other in-memory locking library like [`mutexify`](https://github.com/mafintosh/mutexify), [`mutex-js`](https://github.com/danielglennross/mutex-js), [`await-lock`](https://www.npmjs.com/package/await-lock), and [many more](https://www.npmjs.com/search?q=promise+lock), but with more flexibility in how\nto use it. This makes it sturdier and more practical in many cases.\n\n\n### _simple_ API when that suffices\n\n```javascript\nconst createLock = require('flexlock/createLock') // require('flexlock').createLock works too\n\nconst lock = createLock()\n\nlock(async () =\u003e {\n  // done before the next block\n})\nlock(async () =\u003e {\n  // done after the previous block\n})\n```\n\n### _Timeouts_ in case anther lock never returns\n\n```javascript\nlock(() =\u003e new Promise()) // This never releases the lock\nlock(async () =\u003e {}, 500)\n  .catch(err =\u003e {\n    err.code === 'ETIMEOUT'\n  })\n```\n\n### _Propagation_ of errors and results\n\n```javascript\nasync function business () {\n  try {\n    const important = await lock(async () =\u003e {\n      // do your thing\n      return important\n    })\n    // You can use the important data here.\n  } catch (err) {\n    // Woops, something happened!\n  }\n}\n```\n\n### _Dedicated locks_ for more readable async code\n\n```javascript\nasync function business () {\n  const unlock = await lock()\n  // do your thing\n  unlock()\n}\n```\n\n### _release_ handlers both once and globally\n\n```javascript\nconst lock = createLock(() =\u003e {\n  // called every time the lock is released\n})\n\nlock.released(function () {\n  // called once, next time the lock is released\n})\n\nawait lock.released() // Promise API available as well\n```\n\n### _Namespace_ support for multiple lockers\n\n```javascript\nconst createLocker = require('flexlock/createLocker') // require('flexlock').createLocker works too\n\nconst lock = createLocker()\n\nasync function business (id, content) {\n  await lock(id, async () =\u003e {\n    // do your thing, locked to this id!\n  })\n}\n```\n\n_Implementation note: The locker will use `createLock` per id. It will keep the created lock until all locks\nfor that id are released. Then it will pass the lock to the garbage collector._\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fflexlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinheidegger%2Fflexlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fflexlock/lists"}