race-signal
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

race-signal

codecov CI

Race a promise against an AbortSignal

Table of contents

Install

$ npm i race-signal

Browser <script> tag

Loading this module through a script tag will make it's exports available as RaceSignal in the global namespace.

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

Example

const { raceSignal } = require('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)

API Docs

License

Licensed under either of

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.

Readme

Keywords

none

Package Sidebar

Install

npm i race-signal

Weekly Downloads

13,387

Version

1.0.2

License

Apache-2.0 OR MIT

Unpacked Size

12 kB

Total Files

10

Last publish

Collaborators

  • achingbrain