{"id":17008169,"url":"https://github.com/szikszail/cross-process-lock","last_synced_at":"2025-03-17T09:31:04.532Z","repository":{"id":31267718,"uuid":"127409727","full_name":"szikszail/cross-process-lock","owner":"szikszail","description":"Cross-process file locking solution with lock-queue","archived":false,"fork":false,"pushed_at":"2024-11-19T04:32:25.000Z","size":898,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T22:10:43.192Z","etag":null,"topics":["cross-process-lock","hacktoberfest","lock","unlock"],"latest_commit_sha":null,"homepage":"https://cross-process-lock.6ai.lol","language":"TypeScript","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/szikszail.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-03-30T09:30:30.000Z","updated_at":"2024-11-19T04:32:06.000Z","dependencies_parsed_at":"2024-04-09T19:54:38.335Z","dependency_job_id":"00817517-8dc3-46b0-9024-e2dfa8b2df62","html_url":"https://github.com/szikszail/cross-process-lock","commit_stats":{"total_commits":30,"total_committers":2,"mean_commits":15.0,"dds":0.3666666666666667,"last_synced_commit":"f44fb853d97ebab2710373b0b44dc2ce0a23082e"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szikszail%2Fcross-process-lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szikszail%2Fcross-process-lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szikszail%2Fcross-process-lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szikszail%2Fcross-process-lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szikszail","download_url":"https://codeload.github.com/szikszail/cross-process-lock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243858929,"owners_count":20359260,"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":["cross-process-lock","hacktoberfest","lock","unlock"],"created_at":"2024-10-14T05:27:35.754Z","updated_at":"2025-03-17T09:31:04.188Z","avatar_url":"https://github.com/szikszail.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cross-process-lock\n\n![Downloads](https://img.shields.io/npm/dw/cross-process-lock?style=flat-square)\n![Version@npm](https://img.shields.io/npm/v/cross-process-lock?label=version%40npm\u0026style=flat-square)\n![Version@git](https://img.shields.io/github/package-json/v/szikszail/cross-process-lock/master?label=version%40git\u0026style=flat-square)\n![CI](https://img.shields.io/github/actions/workflow/status/szikszail/cross-process-lock/ci.yml?branch=master\u0026label=ci\u0026style=flat-square) \n![Docs](https://img.shields.io/github/actions/workflow/status/szikszail/cross-process-lock/docs.yml?branch=master\u0026label=docs\u0026style=flat-square)\n\nCross-process file locking solution with lock-queue\n\n## Usage\n\n``` javascript\nconst { lock } = require('cross-process-lock');\nconst { writeFileSync } = require('fs');\n// create a lock for the given file\nconst unlock = await lock('file.txt')\n// do smth with the file here\nwriteFileSync('file.txt', 'some content', 'utf8');\n// unlock file with the received function\nreturn unlock();\n```\n\n## API\n\n### Lock\n\n`lock(file[, options])` - creates a lock for the given file for the actual process\n\n**Arguments**:\n\n* `{string} file` - the path of the file needs to be locked\n* `{lockOptions} options` - the options to use to lock file, e.g timeouts\n\n**Returns**: `Promise\u003cFunction\u003e` - resolved with `unlock` function in case of successful lock; rejected in case of file couldn't be lock in the given timeout\n\n### Unlock\n\n`unlock(file)` - deletes the lock for the given file for the actual process\n\n**Arguments**:\n\n* `{string} file` - the path of the file needs to be unlocked\n\n**Returns**: `Promise` - resolved in case of successful unlock or rejected in case of any error\n\n### WithLock\n\n`withLock(file[, options], callback)` - executes the callback with locking before and unlocking after the execution\n\n**Arguments**:\n* `{string} file` - path of the file needs to be locked\n* `{lockOptions} options` - the options to use to lock file, e.g timeouts\n* `{() =\u003e Promise\u003cT\u003e} callback` - the function to be executed\n\n**Returns**: `Promise\u003cT\u003e` - resolved/rejected with the result of the callback\n\n### lockOptions\n\n| Option                 | Description                                    |  Default   |\n| :--------------------- | :--------------------------------------------- | :--------: |\n| `lockTimeout {number}` | timeout (ms) when locks automatically released | 20 minutes |\n| `waitTimeout {number}` | timeout (ms) until lock waits to lock a file   | 10 seconds |\n\n## Debug\n\nThe package uses the [debug](https://www.npmjs.com/package/debug) NPM package with `cross-process-lock:PID` name, where `PID` is the process ID of the current process.\n\nTo enable debug logging, use for example the `DEBUG=cross-process-lock:*` environment variable, but for more information, check the documentation of the [debug](https://www.npmjs.com/package/debug) package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszikszail%2Fcross-process-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fszikszail%2Fcross-process-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszikszail%2Fcross-process-lock/lists"}