From 938e148c192068387b3084932c387eb335006c75 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Mon, 19 Aug 2024 14:42:18 +0900 Subject: [PATCH] chore: back to all settled --- types/rpc-service.ts | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/types/rpc-service.ts b/types/rpc-service.ts index 1ae8d47..ad7af3b 100644 --- a/types/rpc-service.ts +++ b/types/rpc-service.ts @@ -57,32 +57,8 @@ export class RPCService { throw new Error(rpcUrl); } } - const promises = runtimeRpcs.map((rpcUrl) => requestEndpoint(rpcUrl)); - // async function getFirstSuccessfulRequest(requests: string[]) { - // if (requests.length === 0) { - // throw new Error("All requests failed."); - // } - // const promisesToResolve = requests.map((rpcUrl) => requestEndpoint(rpcUrl)); - // - // try { - // const res = await Promise.race(promisesToResolve); - // if (!res.success) { - // throw new Error(res.rpcUrl); - // } - // return res; - // } catch (err) { - // if (err instanceof Error && requests.includes(err.message)) { - // return getFirstSuccessfulRequest(requests.filter((request) => request !== err.message)); - // } - // return getFirstSuccessfulRequest(requests.slice(1)); - // } - // } - // const fastest = await getFirstSuccessfulRequest(runtimeRpcs); - // - // if (fastest.success) { - // latencies[`${networkId}__${fastest.rpcUrl}`] = fastest.duration; - // } + const promises = runtimeRpcs.map((rpcUrl) => requestEndpoint(rpcUrl)); const allResults = await Promise.allSettled(promises); allResults.forEach((result) => { @@ -96,6 +72,7 @@ export class RPCService { } } }); + return { latencies, runtimeRpcs }; }