From 2bccc5b3ca1df6444c942c715718519d590281e0 Mon Sep 17 00:00:00 2001 From: urugator <11457665+urugator@users.noreply.github.com> Date: Sat, 14 Jan 2023 18:30:52 +0100 Subject: [PATCH] Fix #3582, AbortSignal leaks @types/node (#3583) --- .changeset/quiet-kiwis-rhyme.md | 5 +++++ packages/mobx/src/api/when.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changeset/quiet-kiwis-rhyme.md diff --git a/.changeset/quiet-kiwis-rhyme.md b/.changeset/quiet-kiwis-rhyme.md new file mode 100644 index 000000000..c970fa3ce --- /dev/null +++ b/.changeset/quiet-kiwis-rhyme.md @@ -0,0 +1,5 @@ +--- +"mobx": patch +--- + +fix #3582: AbortSignal leaks @types/node diff --git a/packages/mobx/src/api/when.ts b/packages/mobx/src/api/when.ts index 84c17f6ca..628a33677 100644 --- a/packages/mobx/src/api/when.ts +++ b/packages/mobx/src/api/when.ts @@ -9,11 +9,19 @@ import { allowStateChanges } from "../internal" +// https://github.com/mobxjs/mobx/issues/3582 +interface GenericAbortSignal { + readonly aborted: boolean + onabort?: ((...args: any) => any) | null + addEventListener?: (...args: any) => any + removeEventListener?: (...args: any) => any +} + export interface IWhenOptions { name?: string timeout?: number onError?: (error: any) => void - signal?: AbortSignal + signal?: GenericAbortSignal } export function when( @@ -90,8 +98,8 @@ function whenPromise( disposer() reject(new Error("WHEN_ABORTED")) } - opts?.signal?.addEventListener("abort", abort) - }).finally(() => opts?.signal?.removeEventListener("abort", abort)) + opts?.signal?.addEventListener?.("abort", abort) + }).finally(() => opts?.signal?.removeEventListener?.("abort", abort)) ;(res as any).cancel = cancel return res as any }