4
4
import { IDisposable } from '../../../../common/types' ;
5
5
import { createDeferred , Deferred } from '../../../../common/utils/async' ;
6
6
import { Disposables } from '../../../../common/utils/resourceLifecycle' ;
7
+ import { traceError } from '../../../../logging' ;
7
8
import { PythonEnvInfo } from '../../info' ;
8
9
import { IPythonEnvsIterator , Locator , PythonLocatorQuery } from '../../locator' ;
9
10
@@ -28,15 +29,22 @@ export abstract class LazyResourceBasedLocator<I = PythonEnvInfo> extends Locato
28
29
29
30
private watchersReady ?: Deferred < void > ;
30
31
32
+ /**
33
+ * This can be used to initialize resources when subclasses are created.
34
+ */
35
+ protected async activate ( ) : Promise < void > {
36
+ await this . ensureResourcesReady ( ) ;
37
+ // There is not need to wait for the watchers to get started.
38
+ this . ensureWatchersReady ( ) . ignoreErrors ( ) ;
39
+ }
40
+
31
41
public async dispose ( ) : Promise < void > {
32
42
await this . disposables . dispose ( ) ;
33
43
}
34
44
35
45
public async * iterEnvs ( query ?: PythonLocatorQuery ) : IPythonEnvsIterator < I > {
36
- await this . ensureResourcesReady ( ) ;
46
+ await this . activate ( ) ;
37
47
yield * this . doIterEnvs ( query ) ;
38
- // There is not need to wait for the watchers to get started.
39
- this . ensureWatchersReady ( ) . ignoreErrors ( ) ;
40
48
}
41
49
42
50
/**
@@ -87,7 +95,10 @@ export abstract class LazyResourceBasedLocator<I = PythonEnvInfo> extends Locato
87
95
return ;
88
96
}
89
97
this . resourcesReady = createDeferred < void > ( ) ;
90
- await this . initResources ( ) ;
98
+ await this . initResources ( ) . catch ( ( ex ) => {
99
+ traceError ( ex ) ;
100
+ this . resourcesReady ?. reject ( ex ) ;
101
+ } ) ;
91
102
this . resourcesReady . resolve ( ) ;
92
103
}
93
104
@@ -97,7 +108,10 @@ export abstract class LazyResourceBasedLocator<I = PythonEnvInfo> extends Locato
97
108
return ;
98
109
}
99
110
this . watchersReady = createDeferred < void > ( ) ;
100
- await this . initWatchers ( ) ;
111
+ await this . initWatchers ( ) . catch ( ( ex ) => {
112
+ traceError ( ex ) ;
113
+ this . watchersReady ?. reject ( ex ) ;
114
+ } ) ;
101
115
this . watchersReady . resolve ( ) ;
102
116
}
103
117
}
0 commit comments