From b1a005feaec1472d134ec1153ea964225bdda1d9 Mon Sep 17 00:00:00 2001 From: Akash Kava <39438041+ackava@users.noreply.github.com> Date: Mon, 20 Nov 2023 13:26:13 +0530 Subject: [PATCH] Added support for signal --- src/services/FetchBuilder.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/services/FetchBuilder.ts b/src/services/FetchBuilder.ts index 286253cb..d6153e33 100644 --- a/src/services/FetchBuilder.ts +++ b/src/services/FetchBuilder.ts @@ -1,3 +1,4 @@ +import { CancelToken } from "../core/types"; import JsonError from "./http/JsonError"; export function buildUrl(strings: TemplateStringsArray, ... p: any[]) { @@ -41,6 +42,18 @@ export default class FetchBuilder { private constructor(private readonly request: IRequest) { } + public cancelToken(cancelToken: CancelToken) { + const ac = new AbortController(); + cancelToken.registerForCancel(() => ac.abort()); + return this.signal(ac.signal); + } + + public signal(signal: AbortSignal) { + return this.append({ + signal + }); + } + public form(name: string, value: string) { const body = this.request.body as FormData ?? new FormData(); body.append(name, value);