@@ -21,7 +21,8 @@ import { ExtensionsRegistry } from '../../extensions/common/extensionsRegistry.j
21
21
import { match } from '../../../../base/common/glob.js' ;
22
22
import { URI } from '../../../../base/common/uri.js' ;
23
23
import { IAuthorizationProtectedResourceMetadata , IAuthorizationServerMetadata } from '../../../../base/common/oauth.js' ;
24
- import { raceTimeout } from '../../../../base/common/async.js' ;
24
+ import { raceCancellation , raceTimeout } from '../../../../base/common/async.js' ;
25
+ import { CancellationTokenSource } from '../../../../base/common/cancellation.js' ;
25
26
26
27
export function getAuthenticationProviderActivationEvent ( id : string ) : string { return `onAuthenticationRequest:${ id } ` ; }
27
28
@@ -110,7 +111,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
110
111
111
112
private readonly _delegates : IAuthenticationProviderHostDelegate [ ] = [ ] ;
112
113
113
- private _isDisposable : boolean = false ;
114
+ private _disposedSource = new CancellationTokenSource ( ) ;
114
115
115
116
constructor (
116
117
@IExtensionService private readonly _extensionService : IExtensionService ,
@@ -119,7 +120,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
119
120
@ILogService private readonly _logService : ILogService
120
121
) {
121
122
super ( ) ;
122
- this . _register ( toDisposable ( ( ) => this . _isDisposable = true ) ) ;
123
+ this . _register ( toDisposable ( ( ) => this . _disposedSource . dispose ( true ) ) ) ;
123
124
this . _register ( authenticationAccessService . onDidChangeExtensionSessionAccess ( e => {
124
125
// The access has changed, not the actual session itself but extensions depend on this event firing
125
126
// when they have gained access to an account so this fires that event.
@@ -276,7 +277,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
276
277
}
277
278
278
279
async getSessions ( id : string , scopes ?: string [ ] , options ?: IAuthenticationGetSessionsOptions , activateImmediate : boolean = false ) : Promise < ReadonlyArray < AuthenticationSession > > {
279
- if ( this . _isDisposable ) {
280
+ if ( this . _disposedSource . token . isCancellationRequested ) {
280
281
return [ ] ;
281
282
}
282
283
@@ -297,7 +298,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
297
298
}
298
299
299
300
async createSession ( id : string , scopes : string [ ] , options ?: IAuthenticationCreateSessionOptions ) : Promise < AuthenticationSession > {
300
- if ( this . _isDisposable ) {
301
+ if ( this . _disposedSource . token . isCancellationRequested ) {
301
302
throw new Error ( 'Authentication service is disposed.' ) ;
302
303
}
303
304
@@ -310,7 +311,7 @@ export class AuthenticationService extends Disposable implements IAuthentication
310
311
}
311
312
312
313
async removeSession ( id : string , sessionId : string ) : Promise < void > {
313
- if ( this . _isDisposable ) {
314
+ if ( this . _disposedSource . token . isCancellationRequested ) {
314
315
throw new Error ( 'Authentication service is disposed.' ) ;
315
316
}
316
317
@@ -382,17 +383,23 @@ export class AuthenticationService extends Disposable implements IAuthentication
382
383
if ( provider ) {
383
384
return provider ;
384
385
}
386
+ if ( this . _disposedSource . token . isCancellationRequested ) {
387
+ throw new Error ( 'Authentication service is disposed.' ) ;
388
+ }
385
389
386
- const store = this . _register ( new DisposableStore ( ) ) ;
390
+ const store = new DisposableStore ( ) ;
387
391
try {
388
392
const result = await raceTimeout (
389
- Event . toPromise (
390
- Event . filter (
391
- this . onDidRegisterAuthenticationProvider ,
392
- e => e . id === providerId ,
393
+ raceCancellation (
394
+ Event . toPromise (
395
+ Event . filter (
396
+ this . onDidRegisterAuthenticationProvider ,
397
+ e => e . id === providerId ,
398
+ store
399
+ ) ,
393
400
store
394
401
) ,
395
- store
402
+ this . _disposedSource . token
396
403
) ,
397
404
5000
398
405
) ;
0 commit comments