Skip to content

Commit c8b9446

Browse files
fix(client): avoid memory leak with abort signals
1 parent 576ea68 commit c8b9446

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,10 @@ export class Arcade {
534534
controller: AbortController,
535535
): Promise<Response> {
536536
const { signal, method, ...options } = init || {};
537-
if (signal) signal.addEventListener('abort', () => controller.abort());
537+
const abort = controller.abort.bind(controller);
538+
if (signal) signal.addEventListener('abort', abort, { once: true });
538539

539-
const timeout = setTimeout(() => controller.abort(), ms);
540+
const timeout = setTimeout(abort, ms);
540541

541542
const isReadableBody =
542543
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||

0 commit comments

Comments
 (0)