Ensure that power levels are loaded only once

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-07-14 14:32:39 +05:30
parent 14c00f50fc
commit 8e39aed4b6

View file

@ -414,11 +414,14 @@ export class BaseRoom extends EventEmitter {
} }
async observePowerLevels() { async observePowerLevels() {
if (this._powerLevelLoading) { await this._powerLevelLoading; }
let observable = this._powerLevels; let observable = this._powerLevels;
if (!observable) { if (!observable) {
const powerLevels = await this._loadPowerLevels(); this._powerLevelLoading = this._loadPowerLevels();
const powerLevels = await this._powerLevelLoading;
observable = new RetainedObservableValue(powerLevels, () => { this._powerLevels = null; }); observable = new RetainedObservableValue(powerLevels, () => { this._powerLevels = null; });
this._powerLevels = observable; this._powerLevels = observable;
this._powerLevelLoading = null;
} }
return observable; return observable;
} }