@@ -51,13 +51,16 @@ export class CoreClientProvider {
51
51
52
52
@postConstruct ( )
53
53
protected init ( ) : void {
54
- this . daemon . getPort ( ) . then ( ( port ) => this . create ( port ) ) ;
55
- this . daemon . onDaemonStopped ( ( ) => {
56
- // TODO
54
+ this . daemon . tryGetPort ( ) . then ( ( port ) => {
55
+ if ( port ) {
56
+ this . create ( port ) ;
57
+ }
57
58
} ) ;
59
+ this . daemon . onDaemonStarted ( ( port ) => this . create ( port ) ) ;
60
+ this . daemon . onDaemonStopped ( ( ) => this . closeClient ( ) ) ;
58
61
this . configService . onConfigChange ( async ( ) => {
59
62
const port = await this . daemon . getPort ( ) ;
60
- this . create ( port , 10 ) ; // Due to a config change, run the indexes update immediately.
63
+ this . create ( port , 10 ) ; // Due to a config change, run the indexes update " immediately" .
61
64
} ) ;
62
65
}
63
66
@@ -90,7 +93,7 @@ export class CoreClientProvider {
90
93
port : string ,
91
94
indexesUpdateDelay = 10_000
92
95
) : Promise < CoreClientProvider . Client > {
93
- this . toDisposeBeforeCreate . dispose ( ) ;
96
+ this . closeClient ( ) ;
94
97
const address = this . address ( port ) ;
95
98
const client = await this . createClient ( address ) ;
96
99
this . toDisposeBeforeCreate . pushAll ( [
@@ -129,15 +132,18 @@ export class CoreClientProvider {
129
132
}
130
133
}
131
134
132
- private async useClient (
135
+ private useClient (
133
136
client : CoreClientProvider . Client
134
- ) : Promise < CoreClientProvider . Client > {
135
- // TODO: why async? -> for local testing and `wait`
137
+ ) : CoreClientProvider . Client {
136
138
this . _client = client ;
137
139
this . onClientReadyEmitter . fire ( this . _client ) ;
138
140
return this . _client ;
139
141
}
140
142
143
+ private closeClient ( ) : void {
144
+ return this . toDisposeBeforeCreate . dispose ( ) ;
145
+ }
146
+
141
147
private async createClient (
142
148
address : string
143
149
) : Promise < CoreClientProvider . Client > {
0 commit comments