Skip to content

@aninest/extensions / AbortSignal / addAbortSignal

addAbortSignal()

ts
function addAbortSignal<F>(func, signal): (...args) => unsubscribe

Adds the option to add an AbortSignal to any function which returns a function to undo its effects.

Type Parameters

F extends (...args) => unsubscribe

Parameters

func: F

The function to wrap

signal: AbortSignal

The AbortSignal to use to remove the effect of the function.

Returns

Function

A function with the same parameters as func but returns a function that will remove the effect of func and remove the listener from the AbortSignal.

Parameters

• ...args: Parameters<F>

Returns

unsubscribe

Example

ts
const anim = createAnimation({ x: 0, y: 0 }, getLinearInterp(1))
const someExtension = (anim: Animation<UnknownRecursiveAnimatable>) => {
 // initialize the extension
 return () => {
   // cleanup
 }
}
const controller = new AbortController()
const extension = addAbortSignal(someExtension, controller.signal)
const unsub = extension(anim)
controller.abort() // will remove the extension `someExtension`
unsub() // unsub is now a no-op after the controller is aborted

Defined in

../../extensions/src/abortSignal.ts:30