# promise-lock

> [![NPM Version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]

Latest version **0.0.6** (published 2015-05-21) · WTFPL license · 0 weekly downloads

## Install

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

## 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.6 |
| Published | 2015-05-21 |
| First published | 2015-05-20 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Corporateanon |
| Maintainers | corporateanon |

## Links

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

## Recent versions

- 0.0.6 (latest) — 2015-05-21
- 0.0.5 — 2015-05-21
- 0.0.4 — 2015-05-20
- 0.0.3 — 2015-05-20
- 0.0.2 — 2015-05-20
- 0.0.1 — 2015-05-20

## README

# promise-lock

[![NPM Version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]

[npm-image]: https://img.shields.io/npm/v/promise-lock.svg
[npm-url]: https://npmjs.org/package/promise-lock
[travis-image]: https://travis-ci.org/corporateanon/promise-lock.svg?branch=master
[travis-url]: https://travis-ci.org/corporateanon/promise-lock

## Installation

   npm install promise-lock

## Usage

1. Rejecting concurrent promises

```javascript
    const lock = new PromiseLock();

    lock.on($.get('/foo'))
        .then((res)=>console.log(res))       //<-- will log the result
        .catch((res)=>console.log('Error'));

    lock.on($.get('/bar'))
        .then((res)=>console.log(res))
        .catch((res)=>console.log('Error'));//<-- will log "Error", because the lock is previously set on anothe promise
```

2. Cancelling previously started promise

```javascript
    const lock = new PromiseLock();

    lock.on($.get('/foo'))
        .then((res)=>console.log(res))       //<-- will never run
        .catch((res)=>console.log('Error')); //<-- will never run
    
    lock.cancel();

    lock.on($.get('/bar'))
        .then((res)=>console.log(res))       //<-- will log the result
        .catch((res)=>console.log('Error'));
```

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