Skip to content

Commit 5b23deb

Browse files
committed
Minor refactoring
1 parent c4a8b72 commit 5b23deb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/remote-config/src/client/realtime_handler.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class RealtimeHandler {
9999
const numFailedStreams =
100100
((await this.storage.getRealtimeBackoffMetadata())?.numFailedStreams ||
101101
0) + 1;
102-
const backoffMillis = calculateBackoffMillis(numFailedStreams) * 60;
102+
const backoffMillis = calculateBackoffMillis(numFailedStreams, 60000, 2);
103103
await this.storage.setRealtimeBackoffMetadata({
104104
backoffEndTimeMillis: new Date(
105105
lastFailedStreamTime.getTime() + backoffMillis
@@ -142,6 +142,7 @@ export class RealtimeHandler {
142142
* and canceling the stream reader if they exist.
143143
*/
144144
private closeRealtimeHttpConnection(): void {
145+
// Aborting only when the controller is not null and tab is in foreground.
145146
if (this.controller && !this.isInBackground) {
146147
this.controller.abort();
147148
this.controller = undefined;
@@ -269,7 +270,7 @@ export class RealtimeHandler {
269270
if (fetchResponse.config != null && fetchResponse.templateVersion) {
270271
return fetchResponse.templateVersion >= lastKnownVersion;
271272
}
272-
return false;
273+
return this.storageCache.getLastFetchStatus() === 'success' ;
273274
}
274275

275276
private parseAndValidateConfigUpdateMessage(message: string): string {
@@ -336,10 +337,11 @@ export class RealtimeHandler {
336337
`Fetching config with custom signals: ${JSON.stringify(customSignals)}`
337338
);
338339
}
340+
const abortSignal =new RemoteConfigAbortSignal();
339341
try {
340342
const fetchRequest: FetchRequest = {
341343
cacheMaxAgeMillis: 0,
342-
signal: new RemoteConfigAbortSignal(),
344+
signal: abortSignal,
343345
customSignals: customSignals,
344346
fetchType: 'REALTIME',
345347
fetchAttempt: currentAttempt
@@ -409,10 +411,11 @@ export class RealtimeHandler {
409411
return;
410412
}
411413

412-
const timeTillFetch = this.getRandomInt(4);
414+
const timeTillFetchSeconds = this.getRandomInt(4);
415+
const timeTillFetchInMiliseconds = timeTillFetchSeconds * 1000;
413416
setTimeout(async () => {
414417
await this.fetchLatestConfig(remainingAttempts, targetVersion);
415-
}, timeTillFetch);
418+
}, timeTillFetchInMiliseconds);
416419
}
417420

418421
private async handleNotifications(

0 commit comments

Comments
 (0)