# race-signal

> Race a promise against an AbortSignal

Latest version **2.0.2** (published 2026-08-16) · Apache-2.0 OR MIT license · 0 weekly downloads

## Install

```sh
npm install race-signal
pnpm add race-signal
yarn add race-signal
bun add race-signal
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2026-08-16 |
| First published | 2021-12-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 OR MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 8 |
| Author | Alex Potsides |
| Maintainers | achingbrain |

## Links

- npm: https://www.npmjs.com/package/race-signal
- Repository: https://github.com/achingbrain/race-signal
- Homepage: https://github.com/achingbrain/race-signal#readme
- Issues: https://github.com/achingbrain/race-signal/issues
- npm.io page: https://npm.io/package/race-signal

## Recent versions

- 2.0.2 (latest) — 2026-08-16
- 2.0.1 — 2026-08-16
- 2.0.0 — 2025-08-19
- 1.1.3 — 2025-02-23
- 1.1.2 — 2025-02-21
- 1.1.1 — 2025-02-21
- 1.1.0 — 2024-08-06
- 1.0.3 — 2024-08-06
- 1.0.2 — 2023-11-16
- 1.0.1 — 2023-10-06
- 1.0.0 — 2023-09-24
- 0.1.0 — 2021-12-21

## README

# race-signal

[![codecov](https://img.shields.io/codecov/c/github/achingbrain/race-signal.svg?style=flat-square)](https://codecov.io/gh/achingbrain/race-signal)
[![CI](https://img.shields.io/github/actions/workflow/status/achingbrain/race-signal/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/achingbrain/race-signal/actions/workflows/js-test-and-release.yml?query=branch%3Amain)

> Race a promise against an AbortSignal

# About

<!--

!IMPORTANT!

Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.

To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts

To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.

-->

Pass a promise and an abort signal and await the result.

## Example - Basic usage

```ts
import { raceSignal } from 'race-signal'

const controller = new AbortController()

const promise = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('a value')
  }, 1000)
})

setTimeout(() => {
  controller.abort()
}, 500)

// throws an AbortError
const resolve = await raceSignal(promise, controller.signal)
```

## Example - Overriding errors

By default the thrown error is the `.reason` property of the signal but it's
possible to override this behaviour with the `translateError` option:

```ts
import { raceSignal } from 'race-signal'

const controller = new AbortController()

const promise = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('a value')
  }, 1000)
})

setTimeout(() => {
  controller.abort()
}, 500)

// throws `Error('Oh no!')`
const resolve = await raceSignal(promise, controller.signal, {
  translateError: (signal) => {
    // use `signal`, or don't
    return new Error('Oh no!')
  }
})
```

# Install

```console
$ npm i race-signal
```

## Browser `<script>` tag

Loading this module through a script tag will make its exports available as `RaceSignal` in the global namespace.

```html
<script src="https://unpkg.com/race-signal/dist/index.min.js"></script>
```

# API Docs

- <https://achingbrain.github.io/race-signal>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](https://github.com/achingbrain/race-signal/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/achingbrain/race-signal/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

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