From fb5136c6dd88c5229ae2f402a7d5914ab010b0c3 Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Sat, 14 Dec 2024 16:43:50 +0100 Subject: [PATCH] Use deferred for action dispatcher initialization --- packages/client/src/base/action-dispatcher.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/client/src/base/action-dispatcher.ts b/packages/client/src/base/action-dispatcher.ts index d6c7aa84..9686a295 100644 --- a/packages/client/src/base/action-dispatcher.ts +++ b/packages/client/src/base/action-dispatcher.ts @@ -17,6 +17,7 @@ import { Action, ActionDispatcher, ActionHandlerRegistry, + Deferred, EMPTY_ROOT, GModelRoot, IActionDispatcher, @@ -47,21 +48,29 @@ export class GLSPActionDispatcher extends ActionDispatcher implements IGModelRoo @inject(TYPES.ActionHandlerRegistryProvider) protected override actionHandlerRegistryProvider: () => Promise; protected postUpdateQueue: Action[] = []; + protected initializeDeferred = new Deferred(); + override initialize(): Promise { if (!this.initialized) { - this.initialized = this.doInitialize(); + this.initialized = this.initializeDeferred.promise; + this.doInitialize(); } return this.initialized; } protected async doInitialize(): Promise { - 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 {