From 714ed1039ed93a95b0c90410b29053bb8548e0c9 Mon Sep 17 00:00:00 2001 From: GuillaumeSD Date: Wed, 27 Mar 2024 01:21:47 +0100 Subject: [PATCH] fix : add timeout to lichess cloud eval --- src/lib/lichess.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/lichess.ts b/src/lib/lichess.ts index a1b710a..ff8d418 100644 --- a/src/lib/lichess.ts +++ b/src/lib/lichess.ts @@ -12,9 +12,13 @@ export const getLichessEval = async ( multiPv = 1 ): Promise => { try { + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 200); const res = await fetch( - `https://lichess.org/api/cloud-eval?fen=${fen}&multiPv=${multiPv}` + `https://lichess.org/api/cloud-eval?fen=${fen}&multiPv=${multiPv}`, + { method: "GET", signal: controller.signal } ); + clearTimeout(timeoutId); const data: LichessResponse = await res.json();