@@ -18,13 +18,13 @@ export class RemoteAuthorityResolverService extends Disposable implements IRemot
18
18
private readonly _onDidChangeConnectionData = this . _register ( new Emitter < void > ( ) ) ;
19
19
public readonly onDidChangeConnectionData = this . _onDidChangeConnectionData . event ;
20
20
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 ;
23
24
private readonly _connectionTokens : Map < string , string > ;
24
25
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 ) {
26
27
super ( ) ;
27
- this . _cache = new Map < string , ResolverResult > ( ) ;
28
28
this . _connectionToken = connectionToken ;
29
29
this . _connectionTokens = new Map < string , string > ( ) ;
30
30
if ( resourceUriProvider ) {
@@ -34,13 +34,12 @@ export class RemoteAuthorityResolverService extends Disposable implements IRemot
34
34
}
35
35
36
36
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 ) ;
42
41
}
43
- return this . _cache . get ( authority ) ! ;
42
+ return result ;
44
43
}
45
44
46
45
async getCanonicalURI ( uri : URI ) : Promise < URI > {
@@ -52,19 +51,23 @@ export class RemoteAuthorityResolverService extends Disposable implements IRemot
52
51
return null ;
53
52
}
54
53
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 ;
56
55
return {
57
56
host : resolverResult . authority . host ,
58
57
port : resolverResult . authority . port ,
59
58
connectionToken : connectionToken
60
59
} ;
61
60
}
62
61
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 ) ;
65
64
const defaultPort = ( / ^ h t t p s : / . test ( window . location . href ) ? 443 : 80 ) ;
66
65
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 ;
68
71
}
69
72
70
73
_clearResolvedAuthority ( authority : string ) : void {
0 commit comments