# cancel.it

> Cancelable promise

Latest version **0.2.2** (published 2022-03-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install cancel.it
pnpm add cancel.it
yarn add cancel.it
bun add cancel.it
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2022-03-18 |
| First published | 2019-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Eduard Troshin |
| Maintainers | eazymov |
| Keywords | promise, cancel, cancelable |

## Links

- npm: https://www.npmjs.com/package/cancel.it
- Repository: https://github.com/Eazymov/cancel.it
- Homepage: https://github.com/Eazymov/cancel.it#readme
- Issues: https://github.com/Eazymov/cancel.it/issues
- npm.io page: https://npm.io/package/cancel.it

## 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.2.2 (latest) — 2022-03-18
- 0.2.1 — 2022-03-18
- 0.2.0 — 2022-03-17
- 0.1.3 — 2019-08-17
- 0.1.2 — 2019-08-17
- 0.1.1 — 2019-02-17
- 0.1.0 — 2019-02-17

## README

# cancel.it

[![npm](https://img.shields.io/npm/v/cancel.it.svg)](https://www.npmjs.com/package/cancel.it)
[![License](https://img.shields.io/npm/l/cancel.it.svg)](https://www.npmjs.com/package/cancel.it)
[![Build Status](https://travis-ci.org/Eazymov/cancel.it.svg?branch=master)](https://travis-ci.org/Eazymov/cancel.it)
[![Coverage Status](https://coveralls.io/repos/github/Eazymov/cancel.it/badge.svg?branch=master)](https://coveralls.io/github/Eazymov/cancel.it?branch=master)
![types: typescript/flow](https://img.shields.io/badge/types-typescript%2Fflow-blue.svg)
![](https://img.shields.io/bundlephobia/min/cancel.it.svg?style=flat)
![](https://img.shields.io/bundlephobia/minzip/cancel.it.svg?style=flat)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Eazymov/cancel.it/pulls)

> Cancelable promise | [github.com/Eazymov/cancel.it](https://github.com/Eazymov/cancel.it#readme)

- [Installation](#installation)
- [About](#about)
- [Usage](#usage)
- [Questions](#questions)
- [License](#license)

## Installation

### Direct `<script />` include

The library will be exposed as a global `Cancelable` variable

```html
<script src="https://cdn.jsdelivr.net/npm/cancel.it@latest"></script>
```

**or** via unpkg

```html
<script src="https://unpkg.com/cancel.it@latest"></script>
```

### NPM

```bash
npm install cancel.it --save
```

### Yarn

```bash
yarn add cancel.it
```

## About

A promise wrapper that provides possibility to create cancelable promises and wrap existing ones. Supports both TypeScript and Flow type annotations out of the box. Commonjs and es6-modules compatible

## Usage

```javascript
import Cancelable from 'cancel.it';

// This
const promise = new Promise((resolve, reject) => {
  setTimeout(() => {
    someCondition ? resolve(someValue) : reject(reason);
  }, 1000);
});

// Turns into this
const cancelable = new Cancelable((resolve, reject) => {
  setTimeout(() => {
    someCondition ? resolve(someValue) : reject(reason);
  }, 1000);
});

// OR
const cancelable = Cancelable.from(promise);

cancelable.isCanceled(); // false
cancelable.cancel();
cancelable.isCanceled(); // true

// Will never be fired
cancelable.then(/* ... */);
cancelable.catch(/* ... */);
cancelable.finally(/* ... */);
```

## Questions

If you have any troubles, questions or proposals you can create the [issue](https://github.com/Eazymov/cancel.it/issues)

## License

[MIT](http://opensource.org/licenses/MIT)

Copyright (c) 2019 - present, Eduard Troshin

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