@graphql-hive/gateway-abort-signal-any
Advanced tools
Comparing version 0.0.3 to 0.0.4-alpha-b9b5c5e72b4373e4d3736e267eaba3f15cc59065
# @graphql-hive/gateway-abort-signal-any | ||
## 0.0.4-alpha-b9b5c5e72b4373e4d3736e267eaba3f15cc59065 | ||
### Patch Changes | ||
- [`b9b5c5e`](https://github.com/graphql-hive/gateway/commit/b9b5c5e72b4373e4d3736e267eaba3f15cc59065) Thanks [@ardatan](https://github.com/ardatan)! - Introduce disposable timeout signals. | ||
When `AbortSignal.timeout(MS)` is used, the timer is not cleaned up until it finishes. | ||
This leads to memory leaks when the signal is not used anymore. | ||
This change introduces a disposable timeout signal that cleans up the timer when the signal is disposed, and in the plugins the signal is disposed whenever the operation is completed. | ||
## 0.0.3 | ||
@@ -4,0 +15,0 @@ |
@@ -6,4 +6,8 @@ type AbortSignalFromAny = AbortSignal & { | ||
declare function isAbortSignalFromAny(signal?: AbortSignal | null): signal is AbortSignalFromAny; | ||
declare function createTimeoutSignalWithDispose(timeout: number): { | ||
signal: AbortSignal; | ||
[Symbol.dispose](): void; | ||
}; | ||
declare function abortSignalAny(givenSignals: Iterable<AbortSignal>): AbortSignal | undefined; | ||
export { type AbortSignalFromAny, abortSignalAny, isAbortSignalFromAny }; | ||
export { type AbortSignalFromAny, abortSignalAny, createTimeoutSignalWithDispose, isAbortSignalFromAny }; |
import { registerAbortSignalListener } from '@graphql-tools/utils'; | ||
import { DisposableSymbols } from '@whatwg-node/disposablestack'; | ||
@@ -6,2 +7,20 @@ function isAbortSignalFromAny(signal) { | ||
} | ||
function createTimeoutSignalWithDispose(timeout) { | ||
const ctrl = new AbortController(); | ||
const id = setTimeout( | ||
() => ctrl.abort( | ||
new DOMException( | ||
"The operation was aborted due to timeout", | ||
"TimeoutError" | ||
) | ||
), | ||
timeout | ||
); | ||
return { | ||
signal: ctrl.signal, | ||
[DisposableSymbols.dispose]() { | ||
clearTimeout(id); | ||
} | ||
}; | ||
} | ||
function abortSignalAny(givenSignals) { | ||
@@ -60,2 +79,2 @@ const signals = /* @__PURE__ */ new Set(); | ||
export { abortSignalAny, isAbortSignalFromAny }; | ||
export { abortSignalAny, createTimeoutSignalWithDispose, isAbortSignalFromAny }; |
{ | ||
"name": "@graphql-hive/gateway-abort-signal-any", | ||
"version": "0.0.3", | ||
"version": "0.0.4-alpha-b9b5c5e72b4373e4d3736e267eaba3f15cc59065", | ||
"type": "module", | ||
@@ -41,2 +41,3 @@ "repository": { | ||
"@graphql-tools/utils": "^10.7.0", | ||
"@whatwg-node/disposablestack": "^0.0.5", | ||
"tslib": "^2.8.1" | ||
@@ -43,0 +44,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8992
166
4
+ Added@whatwg-node/disposablestack@0.0.5(transitive)