包详细信息

race-signal

achingbrain164.7kApache-2.0 OR MIT1.1.3

Race a promise against an AbortSignal

自述文件

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.

更新日志

1.1.3 (2025-02-23)

Bug Fixes

1.1.2 (2025-02-21)

Bug Fixes

  • do not leave the promise dangling when the signal is aborted (#64) (6333fbc)

1.1.1 (2025-02-21)

Trivial Changes

Dependencies

  • dev: bump aegir from 44.1.4 to 45.0.8 (#63) (b2bd93e)

1.1.0 (2024-08-06)

Features

1.0.3 (2024-08-06)

Trivial Changes

Dependencies

  • dev: bump aegir from 41.3.5 to 44.1.0 (#57) (2067ab6)

1.0.2 (2023-11-16)

Bug Fixes

1.0.1 (2023-10-06)

Bug Fixes

  • improve stack trace of thrown error (#45) (ae387a8)

Dependencies

  • dev: bump aegir from 40.0.13 to 41.0.0 (#44) (ce1688e)

1.0.0 (2023-09-24)

⚠ BREAKING CHANGES

  • this module is now ESM-only

Features

Trivial Changes

0.1.0 (2021-12-21)