mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 20:41:24 +00:00
perf: use .abort.bind() instead of arrow closures to prevent memory leaks (#7174)
This commit is contained in:
committed by
Peter Steinberger
parent
d637a26350
commit
d9c582627c
@@ -42,7 +42,7 @@ export function wrapFetchWithAbortSignal(fetchImpl: typeof fetch): typeof fetch
|
||||
return fetchImpl(input, patchedInit);
|
||||
}
|
||||
const controller = new AbortController();
|
||||
const onAbort = () => controller.abort();
|
||||
const onAbort = controller.abort.bind(controller);
|
||||
if (signal.aborted) {
|
||||
controller.abort();
|
||||
} else {
|
||||
|
||||
@@ -50,8 +50,8 @@ function buildAbortSignal(params: { timeoutMs?: number; signal?: AbortSignal }):
|
||||
}
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
const onAbort = () => controller.abort();
|
||||
const timeoutId = setTimeout(controller.abort.bind(controller), timeoutMs);
|
||||
const onAbort = controller.abort.bind(controller);
|
||||
if (signal) {
|
||||
if (signal.aborted) {
|
||||
controller.abort();
|
||||
|
||||
@@ -5,7 +5,7 @@ export async function fetchJson(
|
||||
fetchFn: typeof fetch,
|
||||
): Promise<Response> {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
||||
const timer = setTimeout(controller.abort.bind(controller), timeoutMs);
|
||||
try {
|
||||
return await fetchFn(url, { ...init, signal: controller.signal });
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user