1.0.2 • Published 1 year ago

@jcoreio/abortable v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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)
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago