Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 1.25 KB

README.md

File metadata and controls

25 lines (17 loc) · 1.25 KB

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