From 76d906c95a6de6cc0043d8c4c5c3fcddba7f895e Mon Sep 17 00:00:00 2001 From: Megh Rathod Date: Fri, 12 Apr 2024 23:29:42 +0530 Subject: [PATCH] fix: use AbortSignal.timeout instead of setTimeout Signed-off-by: Megh Rathod --- src/backend/metadata/tmdb.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/backend/metadata/tmdb.ts b/src/backend/metadata/tmdb.ts index 0f01d684..f9d21c6c 100644 --- a/src/backend/metadata/tmdb.ts +++ b/src/backend/metadata/tmdb.ts @@ -156,13 +156,6 @@ const headers = { async function get(url: string, params?: object): Promise { if (!apiKey) throw new Error("TMDB API key not set"); - const controller = new AbortController(); - const { signal } = controller; - - const timeoutId = - baseURL === otherUrl - ? setTimeout(() => controller.abort(), 15000) - : setTimeout(() => controller.abort(), 3000); let res: Promise; try { @@ -172,9 +165,8 @@ async function get(url: string, params?: object): Promise { params: { ...params, }, - signal, + signal: AbortSignal.timeout(baseURL !== otherUrl ? 5000 : 30000), }); - clearTimeout(timeoutId); } catch (err) { if (baseURL !== otherUrl) { baseURL = otherUrl;