# lock

> lock asynchronous resources.

Latest version **1.1.0** (published 2017-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install lock
pnpm add lock
yarn add lock
bun add lock
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-09-21 |
| First published | 2013-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 48 |
| Author | Dominic Tarr |
| Maintainers | raymondmayjr, dominictarr |

## Links

- npm: https://www.npmjs.com/package/lock
- Repository: https://github.com/dominictarr/lock
- Issues: https://github.com/dominictarr/lock/issues
- npm.io page: https://npm.io/package/lock

## Recent versions

- 1.1.0 (latest) — 2017-09-21
- 0.1.4 — 2017-07-13
- 0.1.3 — 2016-08-19
- 0.1.2 — 2015-03-26
- 0.1.0 — 2013-12-08
- 0.0.4 — 2013-06-18
- 0.0.3 — 2013-02-11
- 0.0.2 — 2013-02-03
- 0.0.1 — 2013-02-03
- 0.0.0 — 2013-02-03

## README

# lock

lock asynchronous resources.

## Simple Example

``` js
var Lock = require('lock').Lock
var lock = Lock()

lock('key', function (release) { //called when resource is available.

  //do an async operation, and wrap the callback with release.
  someAsyncOperation(args,..., release(function (err) {
    //'key' is now unlocked!
  })
})
```

## Multiple Locks at Once.

``` js
var Lock = require('lock').Lock
var lock = Lock()

lock(['A', 'B', 'C'], function (release) { //called, when ALL
                                           //resources are available.

  //do an async operation, and wrap the callback with release(cb)
  someAsyncOperation(args,..., release(function (err) {
    //A, B & C are now unlocked!
  })
})
```

## Lock with optional callback.

``` js
var Lock = require('lock').Lock
var lock = Lock()

lock('cache', function(release) { //called when no one is writing to cache
	//we do not care if this fails since its a cache so no callback needed
	fs.writeFile(fileCache, ... , release())
})
```

used in [level-update](https://github.com/dominictarr/level-update)

## License

MIT

---
_Source: https://npm.io/package/lock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
