Skip to content

Commit

Permalink
Fix #3582, AbortSignal leaks @types/node (#3583)
Browse files Browse the repository at this point in the history
  • Loading branch information
urugator authored Jan 14, 2023
1 parent 7095fa4 commit 2bccc5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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
}

0 comments on commit 2bccc5b

Please sign in to comment.