Skip to content

Commit

Permalink
Added support for signal
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Nov 20, 2023
1 parent 592ac49 commit b1a005f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/services/FetchBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CancelToken } from "../core/types";
import JsonError from "./http/JsonError";

export function buildUrl(strings: TemplateStringsArray, ... p: any[]) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b1a005f

Please sign in to comment.