# sleep-cancel

> Cancellable sleep function for Typescript

Latest version **1.0.0** (published 2021-03-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install sleep-cancel
pnpm add sleep-cancel
yarn add sleep-cancel
bun add sleep-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 | 1.0.0 |
| Published | 2021-03-18 |
| First published | 2021-03-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Trevor Robinson |
| Maintainers | trevorr |
| Keywords | sleep, delay, cancel, promise, typescript |

## Links

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

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-03-18

## README

# sleep-cancel: Cancellable sleep function for Typescript

[![npm](https://img.shields.io/npm/v/sleep-cancel)](https://www.npmjs.com/package/sleep-cancel)
[![CircleCI](https://img.shields.io/circleci/build/github/trevorr/sleep-cancel)](https://circleci.com/gh/trevorr/sleep-cancel)
[![Coverage Status](https://coveralls.io/repos/github/trevorr/sleep-cancel/badge.svg?branch=master)](https://coveralls.io/github/trevorr/sleep-cancel?branch=master)

A small, simple, promise-based, cancellable delay function for Typescript and Javascript.

## Installation

```sh
npm install sleep-cancel
```

## Basic Usage

```ts
import sleep from 'sleep-cancel';

(async function () {
  console.log('Sleeping at', Date.now());
  await sleep(2000);
  console.log('Woke at', Date.now());
})();
```

## Cancellation Usage

```ts
import sleep, { SleepCancelled } from 'sleep-cancel';

const promise = sleep(2000);

(async function () {
  console.log('Sleeping at', Date.now());
  try {
    await promise;
  } catch (e) {
    if (e instanceof SleepCancelled) {
      console.log('Sleep cancelled')
    } else {
      throw e;
    }
  } finally {
    console.log('Woke at', Date.now());
  }
})();

promise.cancel();
```

## License

`sleep-cancel` is available under the [ISC license](LICENSE).

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