Skip to content

Commit

Permalink
Update relewise.client.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
RAORelewise committed Oct 20, 2023
1 parent 8e90a3c commit c6aa057
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/src/relewise.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ export abstract class RelewiseClient {
private requestDictionary: { [requestUrl: string]: AbortController | null } = {};

private ensureAbortSignal(requestUrl: string): AbortSignal {
let abortController = this.requestDictionary[requestUrl];
const abortController = this.requestDictionary[requestUrl];
if (abortController) {
abortController.abort();
}

abortController = new AbortController();
this.requestDictionary[requestUrl] = abortController;

return abortController.signal;
const newAbortController = new AbortController();
this.requestDictionary[requestUrl] = newAbortController;
return newAbortController.signal;
}

private clearAbortSignal(requestUrl: string) {
Expand Down Expand Up @@ -81,7 +80,7 @@ export abstract class RelewiseClient {
'X-Relewise-Version': version.tag,
},
body: JSON.stringify(data),
...(this._useCancellation && { signal: this.ensureAbortSignal(requestUrl) }),
signal: this._useCancellation ? this.ensureAbortSignal(requestUrl) : undefined,
});

if (!response.ok) {
Expand All @@ -105,6 +104,10 @@ export abstract class RelewiseClient {
return responseMessage as TResponse;
} catch (err) {
return undefined;
} finally {
if (this._useCancellation) {
this.clearAbortSignal(requestUrl);
}
}
}

Expand Down

0 comments on commit c6aa057

Please sign in to comment.