@@ -51,13 +51,16 @@ export class CoreClientProvider {
5151
5252 @postConstruct ( )
5353 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+ }
5758 } ) ;
59+ this . daemon . onDaemonStarted ( ( port ) => this . create ( port ) ) ;
60+ this . daemon . onDaemonStopped ( ( ) => this . closeClient ( ) ) ;
5861 this . configService . onConfigChange ( async ( ) => {
5962 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" .
6164 } ) ;
6265 }
6366
@@ -90,7 +93,7 @@ export class CoreClientProvider {
9093 port : string ,
9194 indexesUpdateDelay = 10_000
9295 ) : Promise < CoreClientProvider . Client > {
93- this . toDisposeBeforeCreate . dispose ( ) ;
96+ this . closeClient ( ) ;
9497 const address = this . address ( port ) ;
9598 const client = await this . createClient ( address ) ;
9699 this . toDisposeBeforeCreate . pushAll ( [
@@ -129,15 +132,18 @@ export class CoreClientProvider {
129132 }
130133 }
131134
132- private async useClient (
135+ private useClient (
133136 client : CoreClientProvider . Client
134- ) : Promise < CoreClientProvider . Client > {
135- // TODO: why async? -> for local testing and `wait`
137+ ) : CoreClientProvider . Client {
136138 this . _client = client ;
137139 this . onClientReadyEmitter . fire ( this . _client ) ;
138140 return this . _client ;
139141 }
140142
143+ private closeClient ( ) : void {
144+ return this . toDisposeBeforeCreate . dispose ( ) ;
145+ }
146+
141147 private async createClient (
142148 address : string
143149 ) : Promise < CoreClientProvider . Client > {
0 commit comments