mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-23 02:31:39 +01:00
Deal with race in a better way
This commit is contained in:
parent
de57e07982
commit
09e67ec21c
@ -132,7 +132,6 @@ export class Session {
|
|||||||
this._createRoomEncryption = this._createRoomEncryption.bind(this);
|
this._createRoomEncryption = this._createRoomEncryption.bind(this);
|
||||||
this._forgetArchivedRoom = this._forgetArchivedRoom.bind(this);
|
this._forgetArchivedRoom = this._forgetArchivedRoom.bind(this);
|
||||||
this.needsKeyBackup = new ObservableValue(false);
|
this.needsKeyBackup = new ObservableValue(false);
|
||||||
this._pendingObserveCalls = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get fingerprintKey() {
|
get fingerprintKey() {
|
||||||
@ -797,8 +796,6 @@ export class Session {
|
|||||||
// now all the collections are updated, update the room status
|
// now all the collections are updated, update the room status
|
||||||
// so any listeners to the status will find the collections
|
// so any listeners to the status will find the collections
|
||||||
// completely up to date
|
// completely up to date
|
||||||
await Promise.all(this._pendingObserveCalls);
|
|
||||||
this._pendingObserveCalls = [];
|
|
||||||
if (this._observedRoomStatus.size !== 0) {
|
if (this._observedRoomStatus.size !== 0) {
|
||||||
for (const ars of archivedRoomStates) {
|
for (const ars of archivedRoomStates) {
|
||||||
if (ars.shouldAdd) {
|
if (ars.shouldAdd) {
|
||||||
@ -941,22 +938,25 @@ export class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async observeRoomStatus(roomId) {
|
async observeRoomStatus(roomId) {
|
||||||
const op = async () => {
|
|
||||||
let observable = this._observedRoomStatus.get(roomId);
|
let observable = this._observedRoomStatus.get(roomId);
|
||||||
if (!observable) {
|
if (!observable) {
|
||||||
const status = await this.getRoomStatus(roomId);
|
let status = undefined;
|
||||||
|
// Create and set the observable with value = undefined, so that
|
||||||
|
// we don't loose any sync changes that come in while we are busy
|
||||||
|
// calculating the current room status.
|
||||||
observable = new RetainedObservableValue(status, () => {
|
observable = new RetainedObservableValue(status, () => {
|
||||||
this._observedRoomStatus.delete(roomId);
|
this._observedRoomStatus.delete(roomId);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._observedRoomStatus.set(roomId, observable);
|
this._observedRoomStatus.set(roomId, observable);
|
||||||
|
status = await this.getRoomStatus(roomId);
|
||||||
|
// If observable.value is not undefined anymore, then some
|
||||||
|
// change has come through the sync.
|
||||||
|
if (observable.get() === undefined) {
|
||||||
|
observable.set(status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return observable;
|
return observable;
|
||||||
}
|
}
|
||||||
const promise = op();
|
|
||||||
this._pendingObserveCalls.push(promise);
|
|
||||||
return await promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
observeRoomState(roomStateHandler) {
|
observeRoomState(roomStateHandler) {
|
||||||
return this._roomStateHandler.subscribe(roomStateHandler);
|
return this._roomStateHandler.subscribe(roomStateHandler);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user