{"_id":"p-lock","_rev":"139754","name":"p-lock","description":"Simple promise lock","dist-tags":{"latest":"2.1.0"},"maintainers":[{"name":"bconnorwhite","email":"connor.bcw@gmail.com"}],"time":{"modified":"2021-06-03T11:26:11.000Z","created":"2021-04-06T01:28:19.501Z","2.1.0":"2021-04-24T20:17:52.027Z","2.0.0":"2021-04-06T02:17:20.065Z","1.0.0":"2021-04-06T01:28:19.501Z"},"users":{},"author":{"name":"Connor White","email":"connor.bcw@gmail.com","url":"https://connorwhite.org"},"repository":{"type":"git","url":"git+https://github.com/bconnorwhite/p-lock.git"},"versions":{"2.1.0":{"name":"p-lock","version":"2.1.0","description":"Simple promise lock","license":"MIT","private":false,"author":{"name":"Connor White","email":"connor.bcw@gmail.com","url":"https://connorwhite.org"},"homepage":"https://connorwhite.org/github/p-lock","repository":{"type":"git","url":"git+https://github.com/bconnorwhite/p-lock.git"},"keywords":["promise","lock","simple","async"],"main":"./build/index.js","scripts":{"build":"bob build","commit":"bob commit","lint":"bob lint","release":"bob publish","test":"bob test"},"devDependencies":{"@bconnorwhite/bob":"^2.9.4"},"eslintConfig":{"extends":"eslint-config-bob"},"husky":{"hooks":{"commit-msg":"bob lint commit"}},"npmpackagejsonlint":{"extends":"npm-package-json-lint-config-bob"},"_id":"p-lock@2.1.0","dist":{"shasum":"6f9dbc55d3aac5b0f75c8ec47f3a6f1b954135f8","size":2538,"noattachment":false,"key":"/p-lock/-/p-lock-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-lock/download/p-lock-2.1.0.tgz"},"_npmUser":{"name":"bconnorwhite","email":"connor.bcw@gmail.com"},"directories":{},"maintainers":[{"name":"bconnorwhite","email":"connor.bcw@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-lock_2.1.0_1619295471801_0.026035470851726528"},"_hasShrinkwrap":false,"publish_time":1619295472027,"_cnpm_publish_time":1619295472027},"2.0.0":{"name":"p-lock","version":"2.0.0","description":"Simple promise lock","license":"MIT","private":false,"author":{"name":"Connor White","email":"connor.bcw@gmail.com","url":"https://connorwhite.org"},"homepage":"https://connorwhite.org/github/p-lock","repository":{"type":"git","url":"git+https://github.com/bconnorwhite/p-lock.git"},"keywords":["promise","lock","simple","async"],"main":"./build/index.js","scripts":{"build":"bob build","commit":"bob commit","lint":"bob lint","release":"bob publish","test":"bob test"},"devDependencies":{"@bconnorwhite/bob":"^2.9.4"},"eslintConfig":{"extends":"eslint-config-bob"},"husky":{"hooks":{"commit-msg":"bob lint commit"}},"npmpackagejsonlint":{"extends":"npm-package-json-lint-config-bob"},"_id":"p-lock@2.0.0","dist":{"shasum":"04bf81ce040f9669cbb4eab297d52ee75a8aa32c","size":1806,"noattachment":false,"key":"/p-lock/-/p-lock-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-lock/download/p-lock-2.0.0.tgz"},"_npmUser":{"name":"bconnorwhite","email":"connor.bcw@gmail.com"},"directories":{},"maintainers":[{"name":"bconnorwhite","email":"connor.bcw@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-lock_2.0.0_1617675439934_0.09723231519011288"},"_hasShrinkwrap":false,"publish_time":1617675440065,"_cnpm_publish_time":1617675440065},"1.0.0":{"name":"p-lock","version":"1.0.0","description":"Simple promise lock","license":"MIT","private":false,"author":{"name":"Connor White","email":"connor.bcw@gmail.com","url":"https://connorwhite.org"},"homepage":"https://connorwhite.org/github/p-lock","repository":{"type":"git","url":"git+https://github.com/bconnorwhite/p-lock.git"},"keywords":["promise","lock","simple","async"],"main":"./build/index.js","scripts":{"build":"bob build","commit":"bob commit","lint":"bob lint","release":"bob publish","test":"bob test"},"devDependencies":{"@bconnorwhite/bob":"^2.9.4"},"eslintConfig":{"extends":"eslint-config-bob"},"husky":{"hooks":{"commit-msg":"bob lint commit"}},"npmpackagejsonlint":{"extends":"npm-package-json-lint-config-bob"},"_id":"p-lock@1.0.0","dist":{"shasum":"8a8bf8b587d45da4ed6dc3c136724bae963aa024","size":1647,"noattachment":false,"key":"/p-lock/-/p-lock-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-lock/download/p-lock-1.0.0.tgz"},"_npmUser":{"name":"bconnorwhite","email":"connor.bcw@gmail.com"},"directories":{},"maintainers":[{"name":"bconnorwhite","email":"connor.bcw@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-lock_1.0.0_1617672499365_0.9231049250337451"},"_hasShrinkwrap":false,"publish_time":1617672499501,"_cnpm_publish_time":1617672499501}},"readme":"<div align=\"center\">\n  <h1>p-lock</h1>\n  <a href=\"https://npmjs.com/package/p-lock\">\n    <img alt=\"NPM\" src=\"https://img.shields.io/npm/v/p-lock.svg\">\n  </a>\n  <a href=\"https://github.com/bconnorwhite/p-lock\">\n    <img alt=\"TypeScript\" src=\"https://img.shields.io/github/languages/top/bconnorwhite/p-lock.svg\">\n  </a>\n  <a href=\"https://coveralls.io/github/bconnorwhite/p-lock?branch=master\">\n    <img alt=\"Coverage Status\" src=\"https://coveralls.io/repos/github/bconnorwhite/p-lock/badge.svg?branch=master\">\n  </a>\n  <a href=\"https://github.com/bconnorwhite/p-lock\">\n    <img alt=\"GitHub Stars\" src=\"https://img.shields.io/github/stars/bconnorwhite/p-lock?label=Stars%20Appreciated%21&style=social\">\n  </a>\n  <a href=\"https://twitter.com/bconnorwhite\">\n    <img alt=\"Twitter Follow\" src=\"https://img.shields.io/twitter/follow/bconnorwhite.svg?label=%40bconnorwhite&style=social\">\n  </a>\n</div>\n\n<br />\n\n> Simple promise lock.\n\n## Installation\n\n```sh\nyarn add p-lock\n```\n\n```sh\nnpm install p-lock\n```\n\n## API\n\n### Usage\n```ts\nimport { writeFile } from \"fs\";\nimport { getLock } from \"p-lock\";\n\nconst lock = getLock();\n\nlock(\"file\").then((release) => {\n  setTimeout(() => {\n    writeFile(\"test.txt\", \"hello\", () => {\n      release();\n    });\n  }, 1000);\n});\n\nlock(\"file\").then((release) => {\n  writeFile(\"test.txt\", \"world\", () => {\n    release();\n  });\n});\n\n// contents of test.txt will be \"world\"\n```\n#### Replace\nReject and replace any promises waiting for the lock, rather than resolving each in series.\n```ts\nimport { writeFile } from \"fs\";\nimport { getLock } from \"p-lock\";\n\nconst lock = getLock({ replace: true });\n\nlet writeCounter = 0;\n\nlock(\"file\").then((release) => {\n  setTimeout(() => {\n    writeCounter += 1;\n    writeFile(\"test.txt\", `update #${writeCounter}`, () => {\n      release();\n    });\n  }, 1000);\n});\n\nlock(\"file\").then((release) => {\n  writeCounter += 1;\n  writeFile(\"test.txt\", `update #${writeCounter}`, () => {\n    release();\n  });\n}).catch(() => {\n  // This promise will reject, since the next one replaces.\n});\n\nlock(\"file\").then((release) => {\n  writeCounter += 1;\n  writeFile(\"test.txt\", `update #${writeCounter}`, () => {\n    release();\n  });\n});\n\n// contents of test.txt will be \"update #2\"\n```\n\n### Types\n```ts\nimport { getLock, LockOptions } from \"p-lock\";\n\nfunction getLock(): Lock;\n\ntype Lock = (key?: string) => Promise<ReleaseFn>;\n\ntype ReleaseFn = () => void;\n\ntype LockOptions = {\n  /**\n   * When aquiring a lock for some key, replace first promise in line rather than adding to queue.\n   * Replaced promise will be rejected.\n   * Default: `false`\n   */\n  replace?: boolean;\n};\n```\n\n<br />\n\n<h2>Dev Dependencies<img align=\"right\" alt=\"David\" src=\"https://img.shields.io/david/dev/bconnorwhite/p-lock.svg\"></h2>\n\n- [@bconnorwhite/bob](https://www.npmjs.com/package/@bconnorwhite/bob): Bob is a toolkit for TypeScript projects\n\n<br />\n\n<h2>License <img align=\"right\" alt=\"license\" src=\"https://img.shields.io/npm/l/p-lock.svg\"></h2>\n\n[MIT](https://opensource.org/licenses/MIT)\n","_attachments":{},"homepage":"https://connorwhite.org/github/p-lock","license":"MIT"}