@@ -45,13 +45,13 @@ export class ExtensionHostProcessManager extends Disposable {
45
45
* A map of already activated events to speed things up if the same activation event is triggered multiple times.
46
46
*/
47
47
private readonly _extensionHostProcessFinishedActivateEvents : { [ activationEvent : string ] : boolean ; } ;
48
- private _extensionHostProcessRPCProtocol : RPCProtocol ;
48
+ private _extensionHostProcessRPCProtocol : RPCProtocol | null ;
49
49
private readonly _extensionHostProcessCustomers : IDisposable [ ] ;
50
50
private readonly _extensionHostProcessWorker : IExtensionHostStarter ;
51
51
/**
52
52
* winjs believes a proxy is a promise because it has a `then` method, so wrap the result in an object.
53
53
*/
54
- private _extensionHostProcessProxy : Promise < { value : ExtHostExtensionServiceShape ; } > ;
54
+ private _extensionHostProcessProxy : Promise < { value : ExtHostExtensionServiceShape ; } | null > | null ;
55
55
56
56
constructor (
57
57
extensionHostProcessWorker : IExtensionHostStarter ,
@@ -67,7 +67,7 @@ export class ExtensionHostProcessManager extends Disposable {
67
67
68
68
this . _extensionHostProcessWorker = extensionHostProcessWorker ;
69
69
this . onDidCrash = this . _extensionHostProcessWorker . onCrashed ;
70
- this . _extensionHostProcessProxy = this . _extensionHostProcessWorker . start ( ) . then (
70
+ this . _extensionHostProcessProxy = this . _extensionHostProcessWorker . start ( ) ! . then (
71
71
( protocol ) => {
72
72
return { value : this . _createExtensionHostCustomers ( protocol ) } ;
73
73
} ,
@@ -105,10 +105,14 @@ export class ExtensionHostProcessManager extends Disposable {
105
105
super . dispose ( ) ;
106
106
}
107
107
108
- private async measure ( ) : Promise < ExtHostLatencyResult > {
109
- const latency = await this . _measureLatency ( ) ;
110
- const down = await this . _measureDown ( ) ;
111
- const up = await this . _measureUp ( ) ;
108
+ private async measure ( ) : Promise < ExtHostLatencyResult | null > {
109
+ const proxy = await this . _getExtensionHostProcessProxy ( ) ;
110
+ if ( ! proxy ) {
111
+ return null ;
112
+ }
113
+ const latency = await this . _measureLatency ( proxy ) ;
114
+ const down = await this . _measureDown ( proxy ) ;
115
+ const up = await this . _measureUp ( proxy ) ;
112
116
return {
113
117
remoteAuthority : this . _remoteAuthority ,
114
118
latency,
@@ -117,10 +121,20 @@ export class ExtensionHostProcessManager extends Disposable {
117
121
} ;
118
122
}
119
123
120
- private async _measureLatency ( ) : Promise < number > {
124
+ private async _getExtensionHostProcessProxy ( ) : Promise < ExtHostExtensionServiceShape | null > {
125
+ if ( ! this . _extensionHostProcessProxy ) {
126
+ return null ;
127
+ }
128
+ const p = await this . _extensionHostProcessProxy ;
129
+ if ( ! p ) {
130
+ return null ;
131
+ }
132
+ return p . value ;
133
+ }
134
+
135
+ private async _measureLatency ( proxy : ExtHostExtensionServiceShape ) : Promise < number > {
121
136
const COUNT = 10 ;
122
137
123
- const { value : proxy } = await this . _extensionHostProcessProxy ;
124
138
let sum = 0 ;
125
139
for ( let i = 0 ; i < COUNT ; i ++ ) {
126
140
const sw = StopWatch . create ( true ) ;
@@ -135,21 +149,19 @@ export class ExtensionHostProcessManager extends Disposable {
135
149
return ( byteCount * 1000 * 8 ) / elapsedMillis ;
136
150
}
137
151
138
- private async _measureUp ( ) : Promise < number > {
152
+ private async _measureUp ( proxy : ExtHostExtensionServiceShape ) : Promise < number > {
139
153
const SIZE = 10 * 1024 * 1024 ; // 10MB
140
154
141
- const { value : proxy } = await this . _extensionHostProcessProxy ;
142
155
let b = Buffer . alloc ( SIZE , Math . random ( ) % 256 ) ;
143
156
const sw = StopWatch . create ( true ) ;
144
157
await proxy . $test_up ( b ) ;
145
158
sw . stop ( ) ;
146
159
return ExtensionHostProcessManager . _convert ( SIZE , sw . elapsed ( ) ) ;
147
160
}
148
161
149
- private async _measureDown ( ) : Promise < number > {
162
+ private async _measureDown ( proxy : ExtHostExtensionServiceShape ) : Promise < number > {
150
163
const SIZE = 10 * 1024 * 1024 ; // 10MB
151
164
152
- const { value : proxy } = await this . _extensionHostProcessProxy ;
153
165
const sw = StopWatch . create ( true ) ;
154
166
await proxy . $test_down ( SIZE ) ;
155
167
sw . stop ( ) ;
@@ -171,9 +183,9 @@ export class ExtensionHostProcessManager extends Disposable {
171
183
this . _register ( this . _extensionHostProcessRPCProtocol . onDidChangeResponsiveState ( ( responsiveState : ResponsiveState ) => this . _onDidChangeResponsiveState . fire ( responsiveState ) ) ) ;
172
184
const extHostContext : IExtHostContext = {
173
185
remoteAuthority : this . _remoteAuthority ,
174
- getProxy : < T > ( identifier : ProxyIdentifier < T > ) : T => this . _extensionHostProcessRPCProtocol . getProxy ( identifier ) ,
175
- set : < T , R extends T > ( identifier : ProxyIdentifier < T > , instance : R ) : R => this . _extensionHostProcessRPCProtocol . set ( identifier , instance ) ,
176
- assertRegistered : ( identifiers : ProxyIdentifier < any > [ ] ) : void => this . _extensionHostProcessRPCProtocol . assertRegistered ( identifiers ) ,
186
+ getProxy : < T > ( identifier : ProxyIdentifier < T > ) : T => this . _extensionHostProcessRPCProtocol ! . getProxy ( identifier ) ,
187
+ set : < T , R extends T > ( identifier : ProxyIdentifier < T > , instance : R ) : R => this . _extensionHostProcessRPCProtocol ! . set ( identifier , instance ) ,
188
+ assertRegistered : ( identifiers : ProxyIdentifier < any > [ ] ) : void => this . _extensionHostProcessRPCProtocol ! . assertRegistered ( identifiers ) ,
177
189
} ;
178
190
179
191
// Named customers
@@ -199,10 +211,12 @@ export class ExtensionHostProcessManager extends Disposable {
199
211
return this . _extensionHostProcessRPCProtocol . getProxy ( ExtHostContext . ExtHostExtensionService ) ;
200
212
}
201
213
202
- public activate ( extension : ExtensionIdentifier , activationEvent : string ) : Promise < boolean > {
203
- return this . _extensionHostProcessProxy . then ( ( proxy ) => {
204
- return proxy . value . $activate ( extension , activationEvent ) ;
205
- } ) ;
214
+ public async activate ( extension : ExtensionIdentifier , activationEvent : string ) : Promise < boolean > {
215
+ const proxy = await this . _getExtensionHostProcessProxy ( ) ;
216
+ if ( ! proxy ) {
217
+ return false ;
218
+ }
219
+ return proxy . $activate ( extension , activationEvent ) ;
206
220
}
207
221
208
222
public activateByEvent ( activationEvent : string ) : Promise < void > {
@@ -241,7 +255,7 @@ export class ExtensionHostProcessManager extends Disposable {
241
255
return 0 ;
242
256
}
243
257
244
- public resolveAuthority ( remoteAuthority : string ) : Promise < ResolvedAuthority > {
258
+ public async resolveAuthority ( remoteAuthority : string ) : Promise < ResolvedAuthority > {
245
259
const authorityPlusIndex = remoteAuthority . indexOf ( '+' ) ;
246
260
if ( authorityPlusIndex === - 1 ) {
247
261
// This authority does not need to be resolved, simply parse the port number
@@ -252,15 +266,27 @@ export class ExtensionHostProcessManager extends Disposable {
252
266
port : parseInt ( pieces [ 1 ] , 10 )
253
267
} ) ;
254
268
}
255
- return this . _extensionHostProcessProxy . then ( proxy => proxy . value . $resolveAuthority ( remoteAuthority ) ) ;
269
+ const proxy = await this . _getExtensionHostProcessProxy ( ) ;
270
+ if ( ! proxy ) {
271
+ throw new Error ( `Cannot resolve authority` ) ;
272
+ }
273
+ return proxy . $resolveAuthority ( remoteAuthority ) ;
256
274
}
257
275
258
- public start ( enabledExtensionIds : ExtensionIdentifier [ ] ) : Promise < void > {
259
- return this . _extensionHostProcessProxy . then ( proxy => proxy . value . $startExtensionHost ( enabledExtensionIds ) ) ;
276
+ public async start ( enabledExtensionIds : ExtensionIdentifier [ ] ) : Promise < void > {
277
+ const proxy = await this . _getExtensionHostProcessProxy ( ) ;
278
+ if ( ! proxy ) {
279
+ return ;
280
+ }
281
+ return proxy . $startExtensionHost ( enabledExtensionIds ) ;
260
282
}
261
283
262
- public deltaExtensions ( toAdd : IExtensionDescription [ ] , toRemove : ExtensionIdentifier [ ] ) : Promise < void > {
263
- return this . _extensionHostProcessProxy . then ( proxy => proxy . value . $deltaExtensions ( toAdd , toRemove ) ) ;
284
+ public async deltaExtensions ( toAdd : IExtensionDescription [ ] , toRemove : ExtensionIdentifier [ ] ) : Promise < void > {
285
+ const proxy = await this . _getExtensionHostProcessProxy ( ) ;
286
+ if ( ! proxy ) {
287
+ return ;
288
+ }
289
+ return proxy . $deltaExtensions ( toAdd , toRemove ) ;
264
290
}
265
291
}
266
292
@@ -328,7 +354,7 @@ interface ExtHostLatencyResult {
328
354
}
329
355
330
356
interface ExtHostLatencyProvider {
331
- measure ( ) : Promise < ExtHostLatencyResult > ;
357
+ measure ( ) : Promise < ExtHostLatencyResult | null > ;
332
358
}
333
359
334
360
let providers : ExtHostLatencyProvider [ ] = [ ] ;
0 commit comments