@@ -39,11 +39,11 @@ export class ArduinoDaemonImpl
39
39
private readonly processUtils : ProcessUtils ;
40
40
41
41
private readonly toDispose = new DisposableCollection ( ) ;
42
- private readonly onDaemonStartedEmitter = new Emitter < string > ( ) ;
42
+ private readonly onDaemonStartedEmitter = new Emitter < number > ( ) ;
43
43
private readonly onDaemonStoppedEmitter = new Emitter < void > ( ) ;
44
44
45
45
private _running = false ;
46
- private _port = new Deferred < string > ( ) ;
46
+ private _port = new Deferred < number > ( ) ;
47
47
48
48
// Backend application lifecycle.
49
49
@@ -53,18 +53,18 @@ export class ArduinoDaemonImpl
53
53
54
54
// Daemon API
55
55
56
- async getPort ( ) : Promise < string > {
56
+ async getPort ( ) : Promise < number > {
57
57
return this . _port . promise ;
58
58
}
59
59
60
- async tryGetPort ( ) : Promise < string | undefined > {
60
+ async tryGetPort ( ) : Promise < number | undefined > {
61
61
if ( this . _running ) {
62
62
return this . _port . promise ;
63
63
}
64
64
return undefined ;
65
65
}
66
66
67
- async start ( ) : Promise < string > {
67
+ async start ( ) : Promise < number > {
68
68
try {
69
69
this . toDispose . dispose ( ) ; // This will `kill` the previously started daemon process, if any.
70
70
const cliPath = this . getExecPath ( ) ;
@@ -101,13 +101,13 @@ export class ArduinoDaemonImpl
101
101
this . toDispose . dispose ( ) ;
102
102
}
103
103
104
- async restart ( ) : Promise < string > {
104
+ async restart ( ) : Promise < number > {
105
105
return this . start ( ) ;
106
106
}
107
107
108
108
// Backend only daemon API
109
109
110
- get onDaemonStarted ( ) : Event < string > {
110
+ get onDaemonStarted ( ) : Event < number > {
111
111
return this . onDaemonStartedEmitter . event ;
112
112
}
113
113
@@ -150,11 +150,11 @@ export class ArduinoDaemonImpl
150
150
151
151
protected async spawnDaemonProcess ( ) : Promise < {
152
152
daemon : ChildProcess ;
153
- port : string ;
153
+ port : number ;
154
154
} > {
155
155
const args = await this . getSpawnArgs ( ) ;
156
156
const cliPath = this . getExecPath ( ) ;
157
- const ready = new Deferred < { daemon : ChildProcess ; port : string } > ( ) ;
157
+ const ready = new Deferred < { daemon : ChildProcess ; port : number } > ( ) ;
158
158
const options = {
159
159
env : { ...deepClone ( process . env ) , NO_COLOR : String ( true ) } ,
160
160
} ;
@@ -195,7 +195,13 @@ export class ArduinoDaemonImpl
195
195
196
196
if ( port . length && address . length ) {
197
197
grpcServerIsReady = true ;
198
- ready . resolve ( { daemon, port } ) ;
198
+ const portNumber = Number . parseInt ( port , 10 ) ;
199
+ if ( Number . isNaN ( portNumber ) ) {
200
+ ready . reject (
201
+ new Error ( `Received a NaN port from the CLI: ${ port } ` )
202
+ ) ;
203
+ }
204
+ ready . resolve ( { daemon, port : portNumber } ) ;
199
205
}
200
206
}
201
207
} ) ;
@@ -225,7 +231,7 @@ export class ArduinoDaemonImpl
225
231
return ready . promise ;
226
232
}
227
233
228
- private fireDaemonStarted ( port : string ) : void {
234
+ private fireDaemonStarted ( port : number ) : void {
229
235
this . _running = true ;
230
236
this . _port . resolve ( port ) ;
231
237
this . onDaemonStartedEmitter . fire ( port ) ;
@@ -238,7 +244,7 @@ export class ArduinoDaemonImpl
238
244
}
239
245
this . _running = false ;
240
246
this . _port . reject ( ) ; // Reject all pending.
241
- this . _port = new Deferred < string > ( ) ;
247
+ this . _port = new Deferred < number > ( ) ;
242
248
this . onDaemonStoppedEmitter . fire ( ) ;
243
249
this . notificationService . notifyDaemonDidStop ( ) ;
244
250
}
0 commit comments