From c0294a617a02b53ac9a4cd2351acb135782b4e15 Mon Sep 17 00:00:00 2001 From: CedarMist <134699267+CedarMist@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:36:28 +0100 Subject: [PATCH] integrations/viem: detect if unref exists on interval --- integrations/viem-v2/src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/integrations/viem-v2/src/index.ts b/integrations/viem-v2/src/index.ts index d051fc57..a5902fa1 100644 --- a/integrations/viem-v2/src/index.ts +++ b/integrations/viem-v2/src/index.ts @@ -127,12 +127,15 @@ export async function createSapphireSerializer< // The fetcher runs in the background, routinely fetching the keys // This means when the serializer requests a calldata public key one will // have been retrieved pre-emptively. - const intervalId = setInterval(async () => { + const intervalId: NodeJS.Timeout | number = setInterval(async () => { await fetcher.fetch(provider); }, fetcher.timeoutMilliseconds); // The interval ID is unreferenced to prevent Node from hanging at exit // See discussion on https://github.com/oasisprotocol/sapphire-paratime/pull/379 - intervalId.unref(); + // This is only available in NodeJS, and not in browsers + if( typeof intervalId.unref === 'function' ) { + intervalId.unref(); + } const wrappedSerializer = ((tx, sig?) => { if (!sig) {