{"_id":"await-semaphore","_rev":"7-94140be795db3cebbaec235950f493a0","name":"await-semaphore","description":"Awaitable semaphore/mutex","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.0":{"name":"await-semaphore","version":"0.1.0","description":"Awaitable semaphore/mutex","main":"index.js","scripts":{"prebuild":"typings install","build":"tsc","test":"mocha test.js"},"repository":{"type":"git","url":"git+https://github.com/notenoughneon/await-semaphore.git"},"keywords":["promise","semaphore","mutex","typescript"],"author":{"name":"Emma Kuo"},"license":"MIT","bugs":{"url":"https://github.com/notenoughneon/await-semaphore/issues"},"homepage":"https://github.com/notenoughneon/await-semaphore#readme","devDependencies":{"mocha":"^2.5.3","typescript":"^1.8.10","typings":"^1.3.1"},"gitHead":"b9f964ceb2eeb4865450b898eea2c01670ff2b05","_id":"await-semaphore@0.1.0","_shasum":"443995335656b4cf7f2a1f8053cccb1b97bc63e5","_from":".","_npmVersion":"3.8.6","_nodeVersion":"6.0.0","_npmUser":{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"},"dist":{"shasum":"443995335656b4cf7f2a1f8053cccb1b97bc63e5","tarball":"https://registry.npmjs.org/await-semaphore/-/await-semaphore-0.1.0.tgz","integrity":"sha512-uqyUe5nSBVlTI/uL636C87seg1N+SldSBlok2F/yKrl/BNRbCOeyAKKdTEDNECiVaFxUEJiJkX3vpYenoZaVxQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHhnWf/kg0yM68CJyiLVLUjpDl3fejuppWYJzK/3wjViAiEA7mhv9wB3+p19JL/VCIwW/hJcNQ6bkCuT+of9J0hGJKo="}]},"maintainers":[{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/await-semaphore-0.1.0.tgz_1469157303383_0.26671332586556673"}},"0.1.1":{"name":"await-semaphore","version":"0.1.1","description":"Awaitable semaphore/mutex","main":"index.js","scripts":{"prebuild":"typings install","build":"tsc","test":"mocha test.js"},"repository":{"type":"git","url":"git+https://github.com/notenoughneon/await-semaphore.git"},"keywords":["promise","semaphore","mutex","typescript"],"author":{"name":"Emma Kuo"},"license":"MIT","bugs":{"url":"https://github.com/notenoughneon/await-semaphore/issues"},"homepage":"https://github.com/notenoughneon/await-semaphore#readme","devDependencies":{"mocha":"^2.5.3","typescript":"^1.8.10","typings":"^1.3.1"},"gitHead":"be88742ea14a1114de566af1f71b538d66ea5793","_id":"await-semaphore@0.1.1","_shasum":"1f47882a27543612e2d0a07cc89fd024568d78c4","_from":".","_npmVersion":"3.8.6","_nodeVersion":"6.0.0","_npmUser":{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"},"dist":{"shasum":"1f47882a27543612e2d0a07cc89fd024568d78c4","tarball":"https://registry.npmjs.org/await-semaphore/-/await-semaphore-0.1.1.tgz","integrity":"sha512-Lg1G7Q/Q8No6XJ/Pr9xyTzQNdR3TF0oNcEKNJqUxr/1RDdxzLUEokZQ5csNBYHeJ+4EU494BVGnLCBQVNgqO3g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDewmz9gzZnprHhiGra9yjoGKDiKr9aDA49pK4mgTiGMAIgEtfGWp0J8PE9cb0/cG0qsqwY3Jm2g3kh2h1LNwTweXI="}]},"maintainers":[{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/await-semaphore-0.1.1.tgz_1469766262454_0.6407655684743077"}},"0.1.2":{"name":"await-semaphore","version":"0.1.2","description":"Awaitable semaphore/mutex","main":"index.js","scripts":{"prebuild":"typings install","build":"tsc","test":"mocha test.js"},"repository":{"type":"git","url":"git+https://github.com/notenoughneon/await-semaphore.git"},"keywords":["promise","semaphore","mutex","typescript"],"author":{"name":"Emma Kuo"},"license":"MIT","bugs":{"url":"https://github.com/notenoughneon/await-semaphore/issues"},"homepage":"https://github.com/notenoughneon/await-semaphore#readme","devDependencies":{"mocha":"^2.5.3","typescript":"^1.8.10","typings":"^1.3.1"},"gitHead":"dd377e3ab5d363947cdb79969bd1b6024a68f0ad","_id":"await-semaphore@0.1.2","_npmVersion":"5.3.0","_nodeVersion":"8.4.0","_npmUser":{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"},"dist":{"integrity":"sha512-3YKBzb5bXSmNNVbNrOCBP1ulNgaXq6O8bZk2n5rzAA4DgbFBgFvSlneMepptFesmUTZn3VzQlEEXYDYu0/+P9A==","shasum":"0ceba1bdb2cfc537496032f167bd8b7dedb97493","tarball":"https://registry.npmjs.org/await-semaphore/-/await-semaphore-0.1.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICBygbmbxHCjUrI2T9rCJ0wEbH1xe73p5YtzfdCRjsXGAiBNkFcnOOT61uihNlqc5ttmbVAl3wm5KtcEXk4g2lHJdA=="}]},"maintainers":[{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/await-semaphore-0.1.2.tgz_1504386989244_0.7936561787500978"}},"0.1.3":{"name":"await-semaphore","version":"0.1.3","description":"Awaitable semaphore/mutex","main":"index.js","scripts":{"prebuild":"typings install","build":"tsc","test":"mocha test.js"},"repository":{"type":"git","url":"git+https://github.com/notenoughneon/await-semaphore.git"},"keywords":["promise","semaphore","mutex","typescript"],"author":{"name":"Emma Kuo"},"license":"MIT","bugs":{"url":"https://github.com/notenoughneon/await-semaphore/issues"},"homepage":"https://github.com/notenoughneon/await-semaphore#readme","devDependencies":{"mocha":"^2.5.3","typescript":"^1.8.10","typings":"^1.3.1"},"gitHead":"f117a6b59324038c9e8ee04c70c328215a727812","_id":"await-semaphore@0.1.3","_npmVersion":"5.3.0","_nodeVersion":"8.4.0","_npmUser":{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"},"dist":{"integrity":"sha512-d1W2aNSYcz/sxYO4pMGX9vq65qOTu0P800epMud+6cYYX0QcT7zyqcxec3VWzpgvdXo57UWmVbZpLMjX2m1I7Q==","shasum":"2b88018cc8c28e06167ae1cdff02504f1f9688d3","tarball":"https://registry.npmjs.org/await-semaphore/-/await-semaphore-0.1.3.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHJtdqDUZi6oEKAznN48k3K+N28r7ExDX6R2CKA/ytigIhAOUY66vuRqbnIiPeeh0oReCEaYLmzEQtGFLDS4HBXhb3"}]},"maintainers":[{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/await-semaphore-0.1.3.tgz_1506547092661_0.11697156191803515"}}},"readme":"# await-semaphore\nAwaitable semaphore/mutex\n\nA semaphore implementation using ES6 promises and supporting 3 styles:\n\n* async/await style (needs typescript)\n* thunk style (automatic acquire/release)\n* promise style\n\nAlso includes `Mutex` as a convenience for `new Semaphore(1)`.\n\n## API\n\n### new Semaphore(count: number)\n\nCreate a new semaphore with the given count.\n\n```javascript\nimport {Semaphore} from 'await-semaphore';\n\nvar semaphore = new Semaphore(10);\n```\n\n### semaphore.acquire(): Promise<() => void>\n\nAcquire the semaphore and returns a promise for the release function. Be sure to handle release for exception case.\n\n```javascript\nsemaphore.acquire()\n.then(release => {\n    //critical section...\n    doSomething()\n    .then(res => {\n        //...\n        release();\n    })\n    .catch(err => {\n        //...\n        release();\n    });\n});\n```\n\n### semaphore.use<T>(thunk: () => Promise<T>): Promise<T>\n\nAlternate method for using the semaphore by providing a thunk. This automatically handles acquire/release.\n\n```javascript\nsemaphore.use(() => {\n    //critical section...\n});\n```\n\n### new Mutex()\n\nAn alias for `new Semaphore(1)`. Mutex has the same methods as Semaphore.\n\n```javascript\nimport {Mutex} from 'await-semaphore';\n\nvar mutex = new Mutex();\n```\n\n## Examples\n\nCreate a version of `fetch()` with concurrency limited to 10.\n\n### async/await style (typescript)\n\n```typescript\nvar semaphore = new Semaphore(10);\n\nasync function niceFetch(url) {\n    var release = await semaphore.acquire();\n    var result = await fetch(url);\n    release();\n    return result;\n}\n```\n\n### thunk style (javascript)\n\n```javascript\nvar semaphore = new Semaphore(10);\n\nfunction niceFetch(url) {\n    return semaphore.use(() => fetch(url));\n}\n```\n\n### promise style (javascript)\n\n```javascript\nvar semaphore = new Semaphore(10);\n\nfunction niceFetch(url) {\n    return semaphore.acquire()\n    .then(release => {\n        return fetch(url)\n        .then(result => {\n            release();\n            return result;\n        });\n    });\n}\n```","maintainers":[{"name":"notenoughneon","email":"emma.c.kuo@gmail.com"}],"time":{"modified":"2022-06-13T03:52:42.866Z","created":"2016-07-22T03:15:03.604Z","0.1.0":"2016-07-22T03:15:03.604Z","0.1.1":"2016-07-29T04:24:22.684Z","0.1.2":"2017-09-02T21:16:29.318Z","0.1.3":"2017-09-27T21:18:12.733Z"},"homepage":"https://github.com/notenoughneon/await-semaphore#readme","keywords":["promise","semaphore","mutex","typescript"],"repository":{"type":"git","url":"git+https://github.com/notenoughneon/await-semaphore.git"},"author":{"name":"Emma Kuo"},"bugs":{"url":"https://github.com/notenoughneon/await-semaphore/issues"},"license":"MIT","readmeFilename":"README.md"}