# locker

> Full-featured client for locker lock server with timeouts support

Latest version **0.1.0** (published 2012-06-10) · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2012-06-10 |
| First published | 2012-06-10 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Ian Babrou |
| Maintainers | bobrik |
| Keywords | lock, server, locker, async, shared, distributed |

## Links

- npm: https://www.npmjs.com/package/locker
- Repository: git@github.com:bobrik/node-locker
- Homepage: https://github.com/bobrik/node-locker
- npm.io page: https://npm.io/package/locker

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2012-06-10

## README

node-locker - full-featured client for [locker](https://github.com/bobrik/locker) lock server
===========================

Allows to lock common resources across servers with sub-second precision in node.js in async way.

## Installation

Check out [locker server](https://github.com/bobrik/locker) page for server installation instructions.

```
npm install locker
```

## Example

```javascript
var Locker = require("locker"),
    locker = new Locker(4545, "127.0.0.1");

locker.on("reset", function() {
    console.log("Reset happened (is server running?)");
});

locker.on("error", function(error) {
    console.log("Catched error:", error);
});

//            name    wait  max   callback
locker.locked("five", 2000, 3000, function(error, callback) {
    if (error) {
        // lock failed
        callback(error);
        return;
    }

    // do whatever you want with your shared resource

    callback(undefined, {well: "done"});
});
```

## API

* Requiring

```javascript
var Locker = require("Locker");
```

* New connection

```javascript
var locker = new Locker(port, host);
```

* Locking resource

```javascript
locker.locked(identifier, lock_wait_time, max_execution_time, callback)
```

`callback` signature:

```javascript
function(error, next) {}
```

In `callback` you will be exclusive owner of resource with name `identifier` if there is no `error` argument.

After doing exclusive stuff you should release lock by calling `next` callback.

### Events

* `reset` — connection was reset and all locks were gone.
* `error` - error occurred on some of connection locks (timeout exceed for waiting or execution time)

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