Skip to content

Commit 24ed0c1

Browse files
Copilotalexr00
andcommitted
Fix disposable leak and handle restart when polling is not active
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 5c56351 commit 24ed0c1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/notifications/notificationsManager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
4848
private _notifications = new Map<string, NotificationTreeItem>();
4949

5050
private _pollingHandler: NodeJS.Timeout | null;
51+
private _pollingDisposable: vscode.Disposable | null;
5152
private _pollingLastModified: string;
5253

5354
private _sortingMethod: NotificationsSortMethod = NotificationsSortMethod.Timestamp;
@@ -70,7 +71,7 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
7071
}
7172
}
7273
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${NOTIFICATIONS_REFRESH_INTERVAL}`)) {
73-
if (this.isPRNotificationsOn() && this._pollingHandler) {
74+
if (this.isPRNotificationsOn()) {
7475
// Restart polling with new interval
7576
this._stopPolling();
7677
this._startPolling();
@@ -447,6 +448,10 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
447448
clearInterval(this._pollingHandler);
448449
this._pollingHandler = null;
449450
}
451+
if (this._pollingDisposable) {
452+
this._pollingDisposable.dispose();
453+
this._pollingDisposable = null;
454+
}
450455
}
451456

452457
private _startPolling() {
@@ -463,7 +468,7 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
463468
refreshInterval * 1000,
464469
this
465470
);
466-
this._register({ dispose: () => clearInterval(this._pollingHandler!) });
471+
this._pollingDisposable = this._register({ dispose: () => clearInterval(this._pollingHandler!) });
467472
}
468473

469474
private _findNotificationKeyForIssueModel(issueModel: IssueModel | PullRequestModel | { owner: string; repo: string; number: number }): string | undefined {

0 commit comments

Comments
 (0)