Skip to content

Commit 860f681

Browse files
authored
fix: switch to polling (#766)
1 parent ea9e2f2 commit 860f681

File tree

4 files changed

+3
-9
lines changed

4 files changed

+3
-9
lines changed

src/repository/adaptive-fetcher.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,23 @@ export class AdaptiveFetcher extends EventEmitter implements FetcherInterface {
5252
return;
5353
}
5454

55-
this.emit(UnleashEvents.Mode, { from: 'streaming', to: 'polling' });
56-
5755
this.currentFetcher.stop();
5856
this.currentFetcher = this.pollingFetcher;
5957

6058
await this.currentFetcher.start();
59+
this.emit(UnleashEvents.Mode, { from: 'streaming', to: 'polling' });
6160
}
6261

6362
private async switchToStreaming() {
6463
if (this.currentFetcher === this.streamingFetcher) {
6564
return;
6665
}
6766

68-
this.emit(UnleashEvents.Mode, { from: 'polling', to: 'streaming' });
69-
7067
this.currentFetcher.stop();
7168
this.currentFetcher = this.streamingFetcher;
7269

7370
await this.currentFetcher.start();
71+
this.emit(UnleashEvents.Mode, { from: 'polling', to: 'streaming' });
7472
}
7573

7674
async start(): Promise<void> {

src/repository/polling-fetcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class PollingFetcher extends EventEmitter implements FetcherInterface {
3232
}
3333

3434
async start(): Promise<void> {
35+
this.stopped = false;
3536
await this.fetch();
3637
}
3738

src/repository/streaming-fetcher.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { FetcherInterface, StreamingFetchingOptions } from './fetcher';
99
export class StreamingFetcher extends EventEmitter implements FetcherInterface {
1010
private eventSource: EventSource | undefined;
1111

12-
private stopped = false;
13-
1412
private options: StreamingFetchingOptions;
1513

1614
constructor(options: StreamingFetchingOptions) {
@@ -85,7 +83,6 @@ export class StreamingFetcher extends EventEmitter implements FetcherInterface {
8583
}
8684

8785
stop() {
88-
this.stopped = true;
8986
if (this.eventSource) {
9087
this.eventSource.close();
9188
this.eventSource = undefined;

src/test/repository.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,6 @@ test('setMode can switch from streaming to polling mode', async (t) => {
19381938
t.is(repo.getMode(), 'polling');
19391939
t.true(eventSource.closed);
19401940

1941-
await repo.fetch();
1942-
19431941
toggles = repo.getToggles();
19441942
t.is(toggles[0].enabled, true);
19451943

0 commit comments

Comments
 (0)