Skip to content

Commit

Permalink
Update getRoot() to use Promise version of EventEmitter.once
Browse files Browse the repository at this point in the history
Co-authored-by: Owen Pearson <[email protected]>
  • Loading branch information
VeskeR and owenpearson committed Oct 22, 2024
1 parent 0e2c3a0 commit d637bd7
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/plugins/liveobjects/liveobjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ export class LiveObjects {
}

async getRoot(): Promise<LiveMap> {
if (!this._syncInProgress) {
// SYNC is finished, can return immediately root object from pool
return this._liveObjectsPool.get(ROOT_OBJECT_ID) as LiveMap;
// SYNC is currently in progress, wait for SYNC sequence to finish
if (this._syncInProgress) {
await this._eventEmitter.once(LiveObjectsEvents.SyncCompleted);
}

// otherwise wait for SYNC sequence to finish
return new Promise((res) => {
this._eventEmitter.once(LiveObjectsEvents.SyncCompleted, () => {
res(this._liveObjectsPool.get(ROOT_OBJECT_ID) as LiveMap);
});
});
return this._liveObjectsPool.get(ROOT_OBJECT_ID) as LiveMap;
}

/**
Expand Down

0 comments on commit d637bd7

Please sign in to comment.