diff --git a/js_modules/dagster-ui/packages/ui-core/src/live-data-provider/LiveDataThread.tsx b/js_modules/dagster-ui/packages/ui-core/src/live-data-provider/LiveDataThread.tsx index 73534ba1ea17f..fff1cc3d1cf47 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/live-data-provider/LiveDataThread.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/live-data-provider/LiveDataThread.tsx @@ -45,6 +45,7 @@ export class LiveDataThread { this.startFetchLoop(); } + private _scheduledStopFetchLoop = false; public unsubscribe(key: string) { if (!this.listenersCount[key]) { return; @@ -53,8 +54,15 @@ export class LiveDataThread { if (this.listenersCount[key] === 0) { delete this.listenersCount[key]; } - if (this.getObservedKeys().length === 0) { - this.stopFetchLoop(); + + if (!this._scheduledStopFetchLoop) { + this._scheduledStopFetchLoop = true; + setTimeout(() => { + if (this.getObservedKeys().length === 0) { + this.stopFetchLoop(); + } + this._scheduledStopFetchLoop = false; + }, 100); } } @@ -62,13 +70,21 @@ export class LiveDataThread { return Object.keys(this.listenersCount); } + private _scheduledStartFetchLoop = false; public startFetchLoop() { - if (this.activeFetches !== this.parallelFetches) { - requestAnimationFrame(this._batchedQueryKeys); - } - if (this.intervals.length !== this.parallelFetches) { - this.intervals.push(setInterval(this._batchedQueryKeys, 5000)); + if (this._scheduledStartFetchLoop) { + return; } + this._scheduledStartFetchLoop = true; + setTimeout(() => { + if (this.activeFetches !== this.parallelFetches) { + requestAnimationFrame(this._batchedQueryKeys); + } + if (this.intervals.length !== this.parallelFetches) { + this.intervals.push(setInterval(this._batchedQueryKeys, 5000)); + } + this._scheduledStartFetchLoop = false; + }, 50); } public stopFetchLoop() {