@jcoreio/abortable
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@jcoreio/abortable

memory-leak-proof function to wrap a promise to reject when a signal is aborted

CircleCI Coverage Status semantic-release npm version

abortable(promise, signal)

Creates a promise that fulfills when the given promise fulfills, or rejects when the given signal is aborted, whichever comes first. If the signal is aborted, rejects with a DOMException with name: 'AbortError'.

Once the returned promise resolves or rejects, references to all promise and signal handlers will have been removed, so that it doesn't unexpectedly retain any memory.

import { abortable } from '@jcoreio/abortable'

const abortController = new AbortContorller()
const { signal } = abortController

const promise = abortable(new Promise((r) => setTimeout(r, 10000)), signal)

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.23latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.23
1.0.14
1.0.03

Package Sidebar

Install

npm i @jcoreio/abortable

Weekly Downloads

10

Version

1.0.2

License

MIT

Unpacked Size

13 kB

Total Files

10

Last publish

Collaborators

  • jrmclaurin
  • jedwards1211
  • eladendorf
  • avramdodson
  • forrest-keller
  • gravitate1838