# ttlfs

> A file-system-based mutex, with a TTL.

Latest version **0.0.1** (published 2014-05-16) · ISC license · 0 weekly downloads

## Install

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

## 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.0.1 |
| Published | 2014-05-16 |
| First published | 2014-05-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| Author | Benjamin Coe |
| Maintainers | bcoe |
| Keywords | fs, lock, mutex |

## Links

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

## Dependencies (3)

- [touch](https://npm.io/package/touch.md) 0.0.3
- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [bluebird](https://npm.io/package/bluebird.md) ^1.2.4

## 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.0.1 (latest) — 2014-05-16

## README

ttlfs
=====

[![Build Status](https://travis-ci.org/npm/ttlfs.png)](https://travis-ci.org/npm/ttlfs)

Create a lock-file with a TTL.

*what is it good for?*

When you want to perform an operation only once in a given block of time, from a single process,
on a single server, e.g., during an NRPE check.

*what isn't it good for?*

When you have multiple processes, in parallel, attempting to acquire a lock.

Usage
-----

```javascript
var ttlfs = require('ttlfs');

// check the ttl on a lock.
ttlfs.ttl('/tmp/awesome.lock', function(err, ttl) {
  if (!ttl) {
    // the lock has expired, we can create
    // a new lock.
    ttlfs.lock('my/tmp/awesome.lock', function(err) {
      if (!err) {
        console.log('we got a lock!');
      }
    });
  }
});

// there is no need to check the ttl.
// an error will occur if the lock can't
// be fetched.
ttlfs.lock('/tmp/awesome.lock', function(err, ttl) {
  if (!err) {
    // do something with the lock.
  } else {
    // we could not get the lock.
  }
});
```

Configuration
-------------

ttlfs accepts the following configuraiton settings:

* **expiry:** when, in ms, should the lock expire? default `60000`.

```javascript
var ttlfs = require('ttlfs').configure({
  expiry: 1800000
});
```

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