Skip to content

Commit

Permalink
Use deferred for action dispatcher initialization (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
tortmayr authored Dec 16, 2024
1 parent 8de5d13 commit 7aec575
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/client/src/base/action-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Action,
ActionDispatcher,
ActionHandlerRegistry,
Deferred,
EMPTY_ROOT,
GModelRoot,
IActionDispatcher,
Expand Down Expand Up @@ -47,21 +48,29 @@ export class GLSPActionDispatcher extends ActionDispatcher implements IGModelRoo
@inject(TYPES.ActionHandlerRegistryProvider) protected override actionHandlerRegistryProvider: () => Promise<ActionHandlerRegistry>;
protected postUpdateQueue: Action[] = [];

protected initializeDeferred = new Deferred<void>();

override initialize(): Promise<void> {
if (!this.initialized) {
this.initialized = this.doInitialize();
this.initialized = this.initializeDeferred.promise;
this.doInitialize();
}
return this.initialized;
}

protected async doInitialize(): Promise<void> {
if (this.actionHandlerRegistry instanceof GLSPActionHandlerRegistry) {
this.actionHandlerRegistry.initialize();
try {
if (this.actionHandlerRegistry instanceof GLSPActionHandlerRegistry) {
this.actionHandlerRegistry.initialize();
}
this.handleAction(SetModelAction.create(EMPTY_ROOT)).catch(() => {
/* Logged in handleAction method */
});
this.startModelInitialization();
this.initializeDeferred.resolve();
} catch (error) {
this.initializeDeferred.reject(error);
}
this.handleAction(SetModelAction.create(EMPTY_ROOT)).catch(() => {
/* Logged in handleAction method */
});
this.startModelInitialization();
}

protected startModelInitialization(): void {
Expand Down

0 comments on commit 7aec575

Please sign in to comment.