# @jameslnewell/cancelable-promise

> A cancelable promise implementation.

Latest version **1.0.2** (published 2018-05-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jameslnewell/cancelable-promise
pnpm add @jameslnewell/cancelable-promise
yarn add @jameslnewell/cancelable-promise
bun add @jameslnewell/cancelable-promise
```

## 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.0.2 |
| Published | 2018-05-28 |
| First published | 2018-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jameslnewell |

## Links

- npm: https://www.npmjs.com/package/@jameslnewell/cancelable-promise
- npm.io page: https://npm.io/package/@jameslnewell/cancelable-promise

## Recent versions

- 1.0.2 (latest) — 2018-05-28
- 1.0.1 — 2018-05-28
- 1.0.0 — 2018-05-28

## README

# @jameslnewell/cancelable-promise 

A cancelable promise implementation.

##### Why?

Unlike other libraries:

* its your choice whether promises are resolved OR rejected
* `.cancel()` is chainable e.g. `promise.then(...).cancel()`

## Installation

```
yarn add @jameslnewell/cancelable-promise 
```

## Usage

```typescript
import CancelablePromise from '@jameslnewell/cancelable-promise';

const start = Date.now();

function delay() {
  return new CancelablePromise((resolve, reject) => {
    const timeout = setTimeout(resolve, 10000);
    return () => {
      clearTimeout(timeout);
      resolve();
    };
  });
}

function exit() {
  process.stdin.end();
  const finish = Date.now();
  const elapsed = (finish - start) / 1000;
  console.log(`Waited ${elapsed} seconds.`);
}

console.log('Waiting 10s before exiting. Press RETURN to exit now.');

const waiting = delay().then(exit, exit);

process.stdin.on('data', data => {
  waiting.cancel();
});
```

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