From 90e95fa03c77e7e172780c6c44b8bf9f3b59255d Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 5 Apr 2023 23:01:57 +0200 Subject: [PATCH 1/2] feat: allow custom setTimeout implementation --- src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/index.ts b/src/index.ts index 9b4d4db..95b9e6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,6 +42,11 @@ export interface EventOptions { */ timeout?: number + /** + * Timeout implementation in case global timeout is not reliable. + */ + setTimeout?: typeof globalThis.setTimeout + /** * Custom resolver to resolve function to be called * @@ -146,6 +151,7 @@ export function createBirpc( serialize = defaultSerialize, deserialize = defaultDeserialize, resolver, + setTimeout = globalThis.setTimeout, timeout = DEFAULT_TIMEOUT, } = options From 33f4721e1c429699ed21b696ba76bcca8f7c7535 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 5 Apr 2023 23:08:25 +0200 Subject: [PATCH 2/2] chore: cleanup --- src/index.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 95b9e6e..f4452c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,11 +42,6 @@ export interface EventOptions { */ timeout?: number - /** - * Timeout implementation in case global timeout is not reliable. - */ - setTimeout?: typeof globalThis.setTimeout - /** * Custom resolver to resolve function to be called * @@ -140,6 +135,9 @@ export const DEFAULT_TIMEOUT = 60_000 // 1 minute const defaultSerialize = (i: any) => i const defaultDeserialize = defaultSerialize +// store setTimeout locally in case it is overriden later +const { setTimeout } = globalThis + export function createBirpc( functions: LocalFunctions, options: BirpcOptions, @@ -151,7 +149,6 @@ export function createBirpc( serialize = defaultSerialize, deserialize = defaultDeserialize, resolver, - setTimeout = globalThis.setTimeout, timeout = DEFAULT_TIMEOUT, } = options