@@ -62,10 +62,8 @@ export class CommonMessageCoordinator {
6262 this . jupyterOutput = this . serviceContainer . get < IOutputChannel > ( IOutputChannel , JUPYTER_OUTPUT_CHANNEL ) ;
6363 }
6464
65- public static async create ( identity : Uri , serviceContainer : IServiceContainer ) : Promise < CommonMessageCoordinator > {
66- const result = new CommonMessageCoordinator ( identity , serviceContainer ) ;
67- await result . initialize ( ) ;
68- return result ;
65+ public static create ( identity : Uri , serviceContainer : IServiceContainer ) : CommonMessageCoordinator {
66+ return new CommonMessageCoordinator ( identity , serviceContainer ) ;
6967 }
7068
7169 public dispose ( ) {
@@ -94,6 +92,19 @@ export class CommonMessageCoordinator {
9492 this . getIPyWidgetScriptSource ( ) ?. onMessage ( message , payload ) ;
9593 }
9694
95+ public async initialize ( ) {
96+ const dispatcher = this . getIPyWidgetMessageDispatcher ( ) ;
97+ const promises = [ ] ;
98+ if ( dispatcher ) {
99+ promises . push ( dispatcher . initialize ( ) ) ;
100+ }
101+ const scriptSource = this . getIPyWidgetScriptSource ( ) ;
102+ if ( scriptSource ) {
103+ promises . push ( scriptSource . initialize ( ) ) ;
104+ }
105+ return Promise . all ( promises ) ;
106+ }
107+
97108 private hash ( s : string ) : string {
98109 return this . hashFn ( ) . update ( s ) . digest ( 'hex' ) ;
99110 }
@@ -164,6 +175,9 @@ export class CommonMessageCoordinator {
164175 this . ipyWidgetMessageDispatcher = this . serviceContainer
165176 . get < IPyWidgetMessageDispatcherFactory > ( IPyWidgetMessageDispatcherFactory )
166177 . create ( this . identity ) ;
178+ this . disposables . push (
179+ this . ipyWidgetMessageDispatcher . postMessage ( this . postEmitter . fire . bind ( this . postEmitter ) )
180+ ) ;
167181 }
168182 return this . ipyWidgetMessageDispatcher ;
169183 }
@@ -183,23 +197,11 @@ export class CommonMessageCoordinator {
183197 this . serviceContainer . get < IPersistentStateFactory > ( IPersistentStateFactory ) ,
184198 this . serviceContainer . get < IExtensionContext > ( IExtensionContext )
185199 ) ;
200+ this . disposables . push ( this . ipyWidgetScriptSource . postMessage ( this . postEmitter . fire . bind ( this . postEmitter ) ) ) ;
201+ this . disposables . push (
202+ this . ipyWidgetScriptSource . postInternalMessage ( this . postEmitter . fire . bind ( this . postEmitter ) )
203+ ) ;
186204 }
187205 return this . ipyWidgetScriptSource ;
188206 }
189-
190- private async initialize ( ) {
191- const dispatcher = this . getIPyWidgetMessageDispatcher ( ) ;
192- const promises = [ ] ;
193- if ( dispatcher ) {
194- this . disposables . push ( dispatcher . postMessage ( this . postEmitter . fire . bind ( this . postEmitter ) ) ) ;
195- promises . push ( dispatcher . initialize ( ) ) ;
196- }
197- const scriptSource = this . getIPyWidgetScriptSource ( ) ;
198- if ( scriptSource ) {
199- this . disposables . push ( scriptSource . postMessage ( this . postEmitter . fire . bind ( this . postEmitter ) ) ) ;
200- this . disposables . push ( scriptSource . postInternalMessage ( this . postEmitter . fire . bind ( this . postEmitter ) ) ) ;
201- promises . push ( scriptSource . initialize ( ) ) ;
202- }
203- return Promise . all ( promises ) ;
204- }
205207}
0 commit comments