refactor: add CancelablePromise sub-type so we can call promise.cancel

This commit is contained in:
Derrick Hammer 2024-03-21 11:34:49 -04:00
parent 0f6495afa8
commit f2d4a146c5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 6 additions and 2 deletions

View File

@ -1,10 +1,14 @@
import Axios, {AxiosError, AxiosRequestConfig} from "axios"; import Axios, {AxiosError, AxiosRequestConfig} from "axios";
import {S5Error} from "#client.js"; import {S5Error} from "#client.js";
export interface CancelablePromise<T> extends Promise<T> {
cancel: () => void;
}
export const customInstance = <T>( export const customInstance = <T>(
config: AxiosRequestConfig, config: AxiosRequestConfig,
options?: AxiosRequestConfig, options?: AxiosRequestConfig,
): Promise<T> => { ): CancelablePromise<T> => {
const source = Axios.CancelToken.source(); const source = Axios.CancelToken.source();
/* /*
@ -33,5 +37,5 @@ export const customInstance = <T>(
source.cancel("Query was cancelled"); source.cancel("Query was cancelled");
}; };
return promise; return promise as CancelablePromise<T>;
}; };