Skip to content

Commit

Permalink
integrations/viem: detect if unref exists on interval
Browse files Browse the repository at this point in the history
  • Loading branch information
CedarMist committed Sep 6, 2024
1 parent 7b74bbe commit 83d5ae5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions integrations/viem-v2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 83d5ae5

Please sign in to comment.