Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3582, AbortSignal leaks @types/node #3583

Merged
merged 7 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-kiwis-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx": patch
---

fix #3582: AbortSignal leaks @types/node
14 changes: 11 additions & 3 deletions packages/mobx/src/api/when.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}