From 4022ded7daa4159de656ae6e9e057e4075704589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Jakub=20Nani=C5=A1ta?= Date: Thu, 7 Nov 2024 12:53:49 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Add=20createDefaultApplicative?= =?UTF-8?q?=20utility=20(#985)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/clean-turtles-hide.md | 5 +++++ packages/devtools/src/common/promise.ts | 17 +++++++++++++++++ packages/devtools/src/omnigraph/config.ts | 6 ++---- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .changeset/clean-turtles-hide.md diff --git a/.changeset/clean-turtles-hide.md b/.changeset/clean-turtles-hide.md new file mode 100644 index 000000000..7e1360694 --- /dev/null +++ b/.changeset/clean-turtles-hide.md @@ -0,0 +1,5 @@ +--- +"@layerzerolabs/devtools": patch +--- + +Add createDefaultApplicative utility diff --git a/packages/devtools/src/common/promise.ts b/packages/devtools/src/common/promise.ts index ce56a0fae..e6f482740 100644 --- a/packages/devtools/src/common/promise.ts +++ b/packages/devtools/src/common/promise.ts @@ -1,4 +1,5 @@ import { Factory } from '@/types' +import { Logger } from '@layerzerolabs/io-devtools' import assert from 'assert' import { backOff } from 'exponential-backoff' @@ -35,6 +36,22 @@ export const sequence = async (tasks: Task[]): Promise => { */ export const parallel = async (tasks: Task[]): Promise => await Promise.all(tasks.map((task) => task())) +/** + * Creates a default applicative based on an environment feature flag. + * + * For now we keep the parallel execution as an opt-in feature flag + * before we have a retry logic fully in place for the SDKs + * + * This is to avoid 429 too many requests errors from the RPCs + * + * @param logger + * @returns + */ +export const createDefaultApplicative = (logger?: Logger) => + process.env.LZ_ENABLE_EXPERIMENTAL_PARALLEL_EXECUTION + ? (logger?.warn(`You are using experimental parallel configuration`), parallel) + : sequence + /** * Maps the errors coming from a task. Errors thrown from the `toError` * callback will not be caught. diff --git a/packages/devtools/src/omnigraph/config.ts b/packages/devtools/src/omnigraph/config.ts index 014b65adf..11da86fe8 100644 --- a/packages/devtools/src/omnigraph/config.ts +++ b/packages/devtools/src/omnigraph/config.ts @@ -3,7 +3,7 @@ import type { Configurator, IOmniSDK, InferOmniEdge, InferOmniNode, OmniGraph, O import type { OmniTransaction } from '@/transactions/types' import { flattenTransactions } from '@/transactions/utils' import { createModuleLogger } from '@layerzerolabs/io-devtools' -import { parallel, sequence } from '@/common/promise' +import { createDefaultApplicative } from '@/common/promise' export type CreateTransactionsFromOmniNodes = Factory< [InferOmniNode, TOmniSDK, TOmniGraph, OmniSDKFactory], @@ -119,9 +119,7 @@ export const createConfigureMultiple = // before we have a retry logic fully in place for the SDKs // // This is to avoid 429 too many requests errors from the RPCs - const applicative = process.env.LZ_ENABLE_EXPERIMENTAL_PARALLEL_EXECUTION - ? (logger.warn(`You are using experimental parallel configuration`), parallel) - : sequence + const applicative = createDefaultApplicative(logger) return flattenTransactions(await applicative(tasks)) }