From d194f0c177023f059736965f7a85c799eb13d859 Mon Sep 17 00:00:00 2001 From: James Hutchison <122519877+JamesHutchison@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:16:01 +0000 Subject: [PATCH] Move socket loop interval to a variable --- src/js/packages/@reactpy/client/src/reactpy-client.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/packages/@reactpy/client/src/reactpy-client.ts b/src/js/packages/@reactpy/client/src/reactpy-client.ts index 005a11473..b840479a0 100644 --- a/src/js/packages/@reactpy/client/src/reactpy-client.ts +++ b/src/js/packages/@reactpy/client/src/reactpy-client.ts @@ -107,6 +107,7 @@ export type SimpleReactPyClientProps = { idleDisconnectTimeSeconds?: number; connectionTimeout?: number; debugMessages?: boolean; + socketLoopThrottle?: number; }; /** @@ -178,6 +179,7 @@ export class SimpleReactPyClient private reconnectedCallback: () => void; private didReconnectingCallback: boolean; private willReconnect: boolean; + private socketLoopThrottle: number; constructor(props: SimpleReactPyClientProps) { super(); @@ -194,6 +196,7 @@ export class SimpleReactPyClient this.lastActivityTime = Date.now() this.reconnectOptions = props.reconnectOptions this.debugMessages = props.debugMessages || false; + this.socketLoopThrottle = props.socketLoopThrottle || 5; this.sleeping = false; this.isReconnecting = false; this.willReconnect = false; @@ -421,7 +424,7 @@ export class SimpleReactPyClient onMessage: async ({ data }) => { this.lastActivityTime = Date.now(); this.handleIncoming(JSON.parse(data)) }, ...this.reconnectOptions, }); - this.socketLoopIntervalId = window.setInterval(() => { this.socketLoop() }, 30); + this.socketLoopIntervalId = window.setInterval(() => { this.socketLoop() }, this.socketLoopThrottle); this.idleCheckIntervalId = window.setInterval(() => { this.idleTimeoutCheck() }, 10000); }, interval)