# task-cancel

> Cancellation mechanism, written in typescript.

Latest version **2.0.0** (published 2018-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install task-cancel
pnpm add task-cancel
yarn add task-cancel
bun add task-cancel
```

## 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 | 2.0.0 |
| Published | 2018-07-29 |
| First published | 2017-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Itay Ronen |
| Maintainers | itayronen |
| Keywords | cancel, cancellation, cancel token, cancelToken, task, async, promise, typescript |

## Links

- npm: https://www.npmjs.com/package/task-cancel
- Homepage: https://gitlab.com/itayronen/task-cancel
- npm.io page: https://npm.io/package/task-cancel

## Dependencies (1)

- [itay-events](https://npm.io/package/itay-events.md) ^3.0.0

## 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

- 2.0.0 (latest) — 2018-07-29
- 1.3.1 — 2018-01-02
- 1.3.0 — 2018-01-02
- 1.2.0 — 2017-07-22
- 1.1.1 — 2017-07-21
- 1.1.0 — 2017-07-19
- 1.0.2 — 2017-07-19
- 1.0.1 — 2017-07-19
- 1.0.0 — 2017-07-19

## README

# task-cancel
Cancellation mechanism, written in typescript.

# Install
`npm install task-cancel`

# Usage
```ts
suite.test("When cancelled, isCancelRequested is true.", test => {
	test.arrange();
	let source = new CancelTokenSource();
	source.cancel();

	test.assert();
	assert.equal(source.token.isCancelRequested, true);
});

suite.test("When cancelled, onCancel is triggered.", test => {
	test.arrange();
	let source = new CancelTokenSource();
	let isTriggered = false;
	source.token.onCancel.add(() => isTriggered = true);

	test.act();
	source.cancel();

	test.assert();
	assert.equal(isTriggered, true);
});

suite.test("When link cancelled, isCancelRequested is true.", test => {
	test.arrange();
	let parent = new CancelTokenSource();
	let source = new CancelTokenSource([parent.token]);

	test.act();
	parent.cancel();

	test.assert();
	assert.equal(source.token.isCancelRequested, true);
});
```

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