Await in fill method to prevent multiple errors

This commit is contained in:
RMidhunSuresh 2022-08-14 17:43:24 +05:30
parent d01a95aae3
commit d1c7a792b8

View file

@ -39,6 +39,17 @@ export class GapTile extends SimpleTile {
console.error(`room.fillGap(): ${err.message}:\n${err.stack}`); console.error(`room.fillGap(): ${err.message}:\n${err.stack}`);
this._error = err; this._error = err;
this.emitChange("error"); this.emitChange("error");
if (err instanceof ConnectionError) {
/*
We need to wait for reconnection here rather than in
notifyVisible() because when we return/throw here
this._loading is set to false and other queued invocations of
this method will succeed and attempt further room.fillGap() calls -
resulting in multiple error entries in logs and elsewhere!
*/
await this._waitForReconnection();
return true;
}
// rethrow so caller of this method // rethrow so caller of this method
// knows not to keep calling this for now // knows not to keep calling this for now
throw err; throw err;
@ -63,8 +74,8 @@ export class GapTile extends SimpleTile {
} }
catch (e) { catch (e) {
if (e instanceof ConnectionError) { if (e instanceof ConnectionError) {
await this.options.client.reconnector.connectionStatus.waitFor(status => status === ConnectionStatus.Online).promise; // Don't increase depth because this gap fill was a noop
canFillMore = true; continue;
} }
} }
depth = depth + 1; depth = depth + 1;
@ -101,6 +112,10 @@ export class GapTile extends SimpleTile {
} }
} }
async _waitForReconnection() {
this.options.client.reconnector.connectionStatus.waitFor(status => status === ConnectionStatus.Online).promise;
}
get shape() { get shape() {
return "gap"; return "gap";
} }