From adb831086994cfcea84aa9013c17e1d7ebcc55eb Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 27 Feb 2024 09:26:16 -0800 Subject: [PATCH] Fixed await and comments --- packages/experiment-core/src/api/stream-api.ts | 8 ++++---- packages/experiment-core/src/transport/stream.ts | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/experiment-core/src/api/stream-api.ts b/packages/experiment-core/src/api/stream-api.ts index 4fedb19e..7efa9abb 100644 --- a/packages/experiment-core/src/api/stream-api.ts +++ b/packages/experiment-core/src/api/stream-api.ts @@ -7,8 +7,8 @@ import { } from '../transport/stream'; const DEFAULT_INITIAL_CONN_TIMEOUT = 1000; // Initial connection timeout. -const MAX_CONN_MS_MIN = 12 * 60 * 1000; // Max connection timeout and wants to automatically disconnect and reconnects. -const MAX_CONN_MS_MAX = 18 * 60 * 1000; // Min timeout as above. +const MAX_CONN_MS_MIN = 12 * 60 * 1000; // Min of max connection timeout and wants to automatically disconnect and reconnects. +const MAX_CONN_MS_MAX = 18 * 60 * 1000; // Max of the above timeout. const KEEP_ALIVE_INTERVAL = (15 + 2) * 1000; // 15 seconds plus 2 seconds grace period. // 0 or neg value disables keep alive. const KEEP_ALIVE_DATA = ' '; @@ -108,7 +108,7 @@ export class SdkStreamApi implements StreamApi { this.reconnectionTimeout = setTimeout(async () => { if (es.readyState == this.eventSourceClass.OPEN) { // The es is being checked, not this.eventSource. So it won't affect new connections. - await this.close(); + this.close(); this.connect(); } }, randomReconnectionTimeout); @@ -151,7 +151,7 @@ export class SdkStreamApi implements StreamApi { } private async error(err: StreamErrorEvent) { - await this.close(); + this.close(); if (this.onError) { try { this.onError(err); diff --git a/packages/experiment-core/src/transport/stream.ts b/packages/experiment-core/src/transport/stream.ts index e42cc248..8625d2db 100644 --- a/packages/experiment-core/src/transport/stream.ts +++ b/packages/experiment-core/src/transport/stream.ts @@ -18,6 +18,7 @@ export interface StreamEventSource { onopen: (evt: StreamOpenEvent) => any; onmessage: (evt: StreamMessageEvent) => any; onerror: (evt: StreamErrorEvent) => any; + // The following are in specs but not currently used. Uncomment as we start to use them. // addEventListener(type: string, listener: (evt: StreamEvent) => void): void; // dispatchEvent(evt: Event): boolean; // removeEventListener(type: string, listener: (evt: StreamEvent) => void): void;