From 93d0d59a3481b5dad18f9ac738341e65690cde7e Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Mon, 6 May 2024 19:34:40 +0000 Subject: [PATCH] lint --- packages/sushi/src/router/data-fetcher.ts | 38 +++++++++---------- packages/sushi/src/router/timeout.test.ts | 27 ++++++------- packages/sushi/src/router/timeout.ts | 23 ++++++----- .../route-processor/test/DataFetcher.test.ts | 8 ++-- 4 files changed, 49 insertions(+), 47 deletions(-) diff --git a/packages/sushi/src/router/data-fetcher.ts b/packages/sushi/src/router/data-fetcher.ts index 2829167e40..e5c76bcbd9 100644 --- a/packages/sushi/src/router/data-fetcher.ts +++ b/packages/sushi/src/router/data-fetcher.ts @@ -63,7 +63,7 @@ export type DataFetcherOptions = { /** Determines if memoizer should be used or not */ memoize?: boolean /** Determines a timeout (in ms) for fetching pools for a token pair */ - fetchPoolsTimeout?: number, + fetchPoolsTimeout?: number } // TODO: Should be a mode on the config for DataFetcher @@ -238,20 +238,20 @@ export class DataFetcher { try { options?.fetchPoolsTimeout ? await promiseTimeout( - provider.fetchPoolsForToken( + provider.fetchPoolsForToken( + currency0.wrapped, + currency1.wrapped, + excludePools, + options, + ), + options.fetchPoolsTimeout, + ) + : await provider.fetchPoolsForToken( currency0.wrapped, currency1.wrapped, excludePools, options, - ), - options.fetchPoolsTimeout - ) - : await provider.fetchPoolsForToken( - currency0.wrapped, - currency1.wrapped, - excludePools, - options, - ) + ) } catch { /**/ } @@ -262,24 +262,24 @@ export class DataFetcher { currency0.wrapped.sortsBefore(currency1.wrapped) ? [currency0.wrapped, currency1.wrapped] : [currency1.wrapped, currency0.wrapped] - try { - options?.fetchPoolsTimeout - ? await promiseTimeout( + try { + options?.fetchPoolsTimeout + ? await promiseTimeout( Promise.allSettled( this.providers.map((p) => p.fetchPoolsForToken(token0, token1, excludePools, options), ), ), - options.fetchPoolsTimeout + options.fetchPoolsTimeout, ) - : await Promise.allSettled( + : await Promise.allSettled( this.providers.map((p) => p.fetchPoolsForToken(token0, token1, excludePools, options), ), ) - } catch { - /**/ - } + } catch { + /**/ + } } } diff --git a/packages/sushi/src/router/timeout.test.ts b/packages/sushi/src/router/timeout.test.ts index a760dd56d5..611eb6d650 100644 --- a/packages/sushi/src/router/timeout.test.ts +++ b/packages/sushi/src/router/timeout.test.ts @@ -1,36 +1,33 @@ -import { describe, expect, it } from 'vitest' +import { describe, it } from 'vitest' import { promiseTimeout } from './timeout.js' -const sleep = async(ms: number, msg = "") => { - let _timeoutReference; - return new Promise( - resolve => _timeoutReference = setTimeout(() => resolve(msg), ms), - ).finally( - () => clearTimeout(_timeoutReference) - ); -}; +const sleep = async (ms: number, msg = '') => { + let _timeoutReference + return new Promise((resolve) => { + _timeoutReference = setTimeout(() => resolve(msg), ms) + return _timeoutReference + }).finally(() => clearTimeout(_timeoutReference)) +} describe('Promise Timeout', async () => { it('should timeout', async () => { - const mainPromise = sleep(1000); + const mainPromise = sleep(1000) await promiseTimeout(mainPromise, 500) .then(() => { - throw "expected to reject, but resolved" + throw 'expected to reject, but resolved' }) .catch(() => { /**/ }) - }) it('should NOT timeout', async () => { - const mainPromise = sleep(1000); + const mainPromise = sleep(1000) await promiseTimeout(mainPromise, 1500) .then(() => { /**/ }) .catch(() => { - throw "expected to resolve, but rejected" + throw 'expected to resolve, but rejected' }) - }) }) diff --git a/packages/sushi/src/router/timeout.ts b/packages/sushi/src/router/timeout.ts index 1c07162f7c..f05d41fd89 100644 --- a/packages/sushi/src/router/timeout.ts +++ b/packages/sushi/src/router/timeout.ts @@ -1,11 +1,14 @@ -export async function promiseTimeout (promise: Promise, time: number, exception?: any) { - let timer: any; +export async function promiseTimeout( + promise: Promise, + time: number, + exception?: any, +) { + let timer: any return Promise.race([ - promise, - new Promise( - (_res, _rej) => timer = setTimeout(_rej, time, exception) - ) - ]).finally( - () => clearTimeout(timer) - ); -}; \ No newline at end of file + promise, + new Promise((_res, _rej) => { + timer = setTimeout(_rej, time, exception) + return timer + }), + ]).finally(() => clearTimeout(timer)) +} diff --git a/protocols/route-processor/test/DataFetcher.test.ts b/protocols/route-processor/test/DataFetcher.test.ts index ecff7a03e6..415494b3c4 100644 --- a/protocols/route-processor/test/DataFetcher.test.ts +++ b/protocols/route-processor/test/DataFetcher.test.ts @@ -12,7 +12,9 @@ async function testDF( ) { if (!t0 || !t1) return const start = performance.now() - await dataFetcher.fetchPoolsForToken(t0, t1, undefined, { fetchPoolsTimeout: 10000 }) + await dataFetcher.fetchPoolsForToken(t0, t1, undefined, { + fetchPoolsTimeout: 10000, + }) const pools = dataFetcher.getCurrentPoolCodeMap(t0, t1) const time = Math.round(performance.now() - start) console.log( @@ -52,9 +54,9 @@ async function runTest() { chName, dataFetcher, SUSHI[chainId as keyof typeof SUSHI], - USDT[chainId as keyof typeof USDT], + FRAX[chainId as keyof typeof FRAX], 'SUSHI', - 'USDT', + 'FRAX', ) await testDF( chName,