refactor: use our own abort controller

This commit is contained in:
Derrick Hammer 2024-03-21 16:15:04 -04:00
parent 6cdf8e40b9
commit f7a760051f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 6 additions and 2 deletions

View File

@ -11,13 +11,17 @@ async function getIsManifest(s5: S5Client, hash: string): Promise<boolean | numb
let type: number | null; let type: number | null;
try { try {
const abort = new AbortController();
const resp = s5.downloadData(hash, { const resp = s5.downloadData(hash, {
onDownloadProgress: (progressEvent: AxiosProgressEvent) => { onDownloadProgress: (progressEvent: AxiosProgressEvent) => {
if (progressEvent.loaded >= 10) { if (progressEvent.loaded >= 10) {
resp.cancel(); abort.abort();
} }
}, },
}) as CancelablePromise<ArrayBuffer>; httpConfig: {
signal: abort.signal,
},
});
const data = await resp; const data = await resp;
const unpacker = Unpacker.fromPacked(Buffer.from(data)); const unpacker = Unpacker.fromPacked(Buffer.from(data));