CommentController: Fix 'discussiontoolscompare' polling not stopping

The .always() callback can be called after .teardown(), and would
previously restart the polling.

Bug: T313096
Change-Id: I6e4c0f7d47e13bd4a259282a508afcdf0c1bd949
This commit is contained in:
Bartosz Dziewoński 2022-12-01 22:09:42 +01:00
parent 51ed8a21f6
commit 7dc35aa3ad

View file

@ -49,6 +49,7 @@ function CommentController( $pageContainer, threadItem, threadItemSet ) {
// Mixin constructors
OO.EventEmitter.call( this );
this.isTornDown = false;
this.$pageContainer = $pageContainer;
this.threadItem = threadItem;
this.threadItemSet = threadItemSet;
@ -280,6 +281,9 @@ CommentController.prototype.startPoll = function () {
commentController.oldId = result.torevid;
} ).always( function () {
if ( commentController.isTornDown ) {
return;
}
commentController.pollTimeout = setTimeout( commentController.startPoll.bind( commentController ), 5000 );
} );
};
@ -375,6 +379,7 @@ CommentController.prototype.teardown = function ( mode ) {
this.stopPoll();
$( document ).off( 'visibilitychange', this.onVisibilityChangeHandler );
this.isTornDown = true;
this.emit( 'teardown', mode );
};