@@ -18,13 +18,13 @@ export class RemoteAuthorityResolverService extends Disposable implements IRemot
1818 private readonly _onDidChangeConnectionData = this . _register ( new Emitter < void > ( ) ) ;
1919 public readonly onDidChangeConnectionData = this . _onDidChangeConnectionData . event ;
2020
21- private readonly _cache : Map < string , ResolverResult > ;
22- private readonly _connectionToken : string | undefined ;
21+ private readonly _promiseCache = new Map < string , Promise < ResolverResult > > ( ) ;
22+ private readonly _cache = new Map < string , ResolverResult > ( ) ;
23+ private readonly _connectionToken : Promise < string > | string | undefined ;
2324 private readonly _connectionTokens : Map < string , string > ;
2425
25- constructor ( @IProductService productService : IProductService , connectionToken : string | undefined , resourceUriProvider : ( ( uri : URI ) => URI ) | undefined ) {
26+ constructor ( @IProductService productService : IProductService , connectionToken : Promise < string > | string | undefined , resourceUriProvider : ( ( uri : URI ) => URI ) | undefined ) {
2627 super ( ) ;
27- this . _cache = new Map < string , ResolverResult > ( ) ;
2828 this . _connectionToken = connectionToken ;
2929 this . _connectionTokens = new Map < string , string > ( ) ;
3030 if ( resourceUriProvider ) {
@@ -34,13 +34,12 @@ export class RemoteAuthorityResolverService extends Disposable implements IRemot
3434 }
3535
3636 async resolveAuthority ( authority : string ) : Promise < ResolverResult > {
37- if ( ! this . _cache . has ( authority ) ) {
38- const result = this . _doResolveAuthority ( authority ) ;
39- RemoteAuthorities . set ( authority , result . authority . host , result . authority . port ) ;
40- this . _cache . set ( authority , result ) ;
41- this . _onDidChangeConnectionData . fire ( ) ;
37+ let result = this . _promiseCache . get ( authority ) ;
38+ if ( ! result ) {
39+ result = this . _doResolveAuthority ( authority ) ;
40+ this . _promiseCache . set ( authority , result ) ;
4241 }
43- return this . _cache . get ( authority ) ! ;
42+ return result ;
4443 }
4544
4645 async getCanonicalURI ( uri : URI ) : Promise < URI > {
@@ -52,19 +51,23 @@ export class RemoteAuthorityResolverService extends Disposable implements IRemot
5251 return null ;
5352 }
5453 const resolverResult = this . _cache . get ( authority ) ! ;
55- const connectionToken = this . _connectionTokens . get ( authority ) || this . _connectionToken ;
54+ const connectionToken = this . _connectionTokens . get ( authority ) || resolverResult . authority . connectionToken ;
5655 return {
5756 host : resolverResult . authority . host ,
5857 port : resolverResult . authority . port ,
5958 connectionToken : connectionToken
6059 } ;
6160 }
6261
63- private _doResolveAuthority ( authority : string ) : ResolverResult {
64- const connectionToken = this . _connectionTokens . get ( authority ) || this . _connectionToken ;
62+ private async _doResolveAuthority ( authority : string ) : Promise < ResolverResult > {
63+ const connectionToken = await Promise . resolve ( this . _connectionTokens . get ( authority ) || this . _connectionToken ) ;
6564 const defaultPort = ( / ^ h t t p s : / . test ( window . location . href ) ? 443 : 80 ) ;
6665 const { host, port } = parseAuthorityWithOptionalPort ( authority , defaultPort ) ;
67- return { authority : { authority, host : host , port : port , connectionToken } } ;
66+ const result : ResolverResult = { authority : { authority, host : host , port : port , connectionToken } } ;
67+ RemoteAuthorities . set ( authority , result . authority . host , result . authority . port ) ;
68+ this . _cache . set ( authority , result ) ;
69+ this . _onDidChangeConnectionData . fire ( ) ;
70+ return result ;
6871 }
6972
7073 _clearResolvedAuthority ( authority : string ) : void {
0 commit comments