@@ -201,14 +201,6 @@ interface IWorkbenchConstructionOptions {
201201
202202interface IWorkbench {
203203 commands : {
204-
205- /**
206- * Allows to execute any command if known with the provided arguments.
207- *
208- * @param command Identifier of the command to execute.
209- * @param rest Parameters passed to the command function.
210- * @return A promise that resolves to the returned value of the given command.
211- */
212204 executeCommand ( command : string , ...args : any [ ] ) : Promise < unknown > ;
213205 }
214206}
@@ -218,11 +210,11 @@ interface IWorkbench {
218210 *
219211 * @param domElement the container to create the workbench in
220212 * @param options for setting up the workbench
221- *
222- * @returns the workbench API facade.
223213 */
224214let created = false ;
225- async function create ( domElement : HTMLElement , options : IWorkbenchConstructionOptions ) : Promise < IWorkbench > {
215+ let workbenchPromiseResolve : Function ;
216+ const workbenchPromise = new Promise < IWorkbench > ( resolve => workbenchPromiseResolve = resolve ) ;
217+ async function create ( domElement : HTMLElement , options : IWorkbenchConstructionOptions ) : Promise < void > {
226218
227219 // Assert that the workbench is not created more than once. We currently
228220 // do not support this and require a full context switch to clean-up.
@@ -232,8 +224,9 @@ async function create(domElement: HTMLElement, options: IWorkbenchConstructionOp
232224 created = true ;
233225 }
234226
235- // Startup workbench
227+ // Startup workbench and resolve waiters
236228 const workbench = await main ( domElement , options ) ;
229+ workbenchPromiseResolve ( workbench ) ;
237230
238231 // Register commands if any
239232 if ( Array . isArray ( options . commands ) ) {
@@ -245,8 +238,25 @@ async function create(domElement: HTMLElement, options: IWorkbenchConstructionOp
245238 } ) ;
246239 }
247240 }
241+ }
242+
243+
244+ //#region API Facade
248245
249- return workbench ;
246+ namespace commands {
247+
248+ /**
249+ * Allows to execute any command if known with the provided arguments.
250+ *
251+ * @param command Identifier of the command to execute.
252+ * @param rest Parameters passed to the command function.
253+ * @return A promise that resolves to the returned value of the given command.
254+ */
255+ export async function executeCommand ( command : string , ...args : any [ ] ) : Promise < unknown > {
256+ const workbench = await workbenchPromise ;
257+
258+ return workbench . commands . executeCommand ( command , ...args ) ;
259+ }
250260}
251261
252262export {
@@ -313,5 +323,8 @@ export {
313323 IShowPortCandidate ,
314324
315325 // Commands
316- ICommand
326+ ICommand ,
327+ commands
317328} ;
329+
330+ //#endregion
0 commit comments