# lockup

> Lockup uses a certain lock file to queue and deal with inter-process asynchronous resources.

Latest version **0.1.1** (published 2013-09-26) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2013-09-26 |
| First published | 2013-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kael |
| Maintainers | kael |
| Keywords | lock, lockup, fs, file, queue, patch, locker, process, inter-process |

## Links

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

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2013-09-26
- 0.1.0 — 2013-08-22

## README

# Lockup

Lockup uses a certain lock file to queue and deal with inter-process asynchronous resources.

## Installation

	npm install lockup --save
	
## Usage

```js
var lockup = require('lockup');
```

### lockup.lock(file [, options={}], callback);

Create a lock if the lock is not existed, and run the `callback` function.

If the lock already exists, `callback` will put in a queue which will be executed and cleaned up once the lock is released.

Notice that, `lockup.lock` could work with multiple `process`es.

##### file `path`

The path of the lock file.

##### options `Object={}`

Optional, default to `{}`;

##### callback `function(err)`

The callback function.

##### err `Error|String`

`Error` instance or error message.


### lockup.unlock(file)

Release a lock.


## Examples

```js
var file = 'foo.lock';
var counter = 0;

function foo(delay){
    var c = counter ++;

    lockup.lock(file, function (err) {
        setTimeout(function () {
        	console.log('counter', c);
        	
        	// release the lock.
            lockup.unlock(file);
        }, delay);
    });
}

foo(1000);
foo(0); // without `lockup.lock`, "counter 1" will be printed first.

// Then print:
// counter 0
// counter 1
```

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