Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/repository/adaptive-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,23 @@ export class AdaptiveFetcher extends EventEmitter implements FetcherInterface {
return;
}

this.emit(UnleashEvents.Mode, { from: 'streaming', to: 'polling' });

this.currentFetcher.stop();
this.currentFetcher = this.pollingFetcher;

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

private async switchToStreaming() {
if (this.currentFetcher === this.streamingFetcher) {
return;
}

this.emit(UnleashEvents.Mode, { from: 'polling', to: 'streaming' });

this.currentFetcher.stop();
this.currentFetcher = this.streamingFetcher;

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

async start(): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions src/repository/polling-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class PollingFetcher extends EventEmitter implements FetcherInterface {
}

async start(): Promise<void> {
this.stopped = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a bug preventing updates after switching from streaming to polling multiple times

await this.fetch();
}

Expand Down
3 changes: 0 additions & 3 deletions src/repository/streaming-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { FetcherInterface, StreamingFetchingOptions } from './fetcher';
export class StreamingFetcher extends EventEmitter implements FetcherInterface {
private eventSource: EventSource | undefined;

private stopped = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this variable in streaming since we have event listener that we register and unregister


private options: StreamingFetchingOptions;

constructor(options: StreamingFetchingOptions) {
Expand Down Expand Up @@ -85,7 +83,6 @@ export class StreamingFetcher extends EventEmitter implements FetcherInterface {
}

stop() {
this.stopped = true;
if (this.eventSource) {
this.eventSource.close();
this.eventSource = undefined;
Expand Down
2 changes: 0 additions & 2 deletions src/test/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,6 @@ test('setMode can switch from streaming to polling mode', async (t) => {
t.is(repo.getMode(), 'polling');
t.true(eventSource.closed);

await repo.fetch();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test will now work without manual fetch trigger and based on the mode change alone


toggles = repo.getToggles();
t.is(toggles[0].enabled, true);

Expand Down
Loading