From aea550fe334795a2e33bc0f66f64693b024c87e6 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Wed, 13 Jul 2022 10:29:18 +0200 Subject: [PATCH] rename Signed-off-by: Akos Kitta --- .../src/node/board-discovery.ts | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/arduino-ide-extension/src/node/board-discovery.ts b/arduino-ide-extension/src/node/board-discovery.ts index f3a2eac4..17e2c449 100644 --- a/arduino-ide-extension/src/node/board-discovery.ts +++ b/arduino-ide-extension/src/node/board-discovery.ts @@ -81,7 +81,10 @@ export class BoardDiscovery stop(): Promise { this.logger.info('>>> Stopping boards watcher...'); return new Promise((resolve, reject) => { - const timeout = this.timeout(BoardDiscovery.StopWatchTimeout, reject); + const timeout = this.createTimeout( + BoardDiscovery.StopWatchTimeout, + reject + ); const toDispose = new DisposableCollection(); toDispose.pushAll([ timeout, @@ -107,7 +110,7 @@ export class BoardDiscovery }); } - private timeout( + private createTimeout( after: number, onTimeout: (error: Error) => void ): Disposable { @@ -118,37 +121,22 @@ export class BoardDiscovery return Disposable.create(() => clearTimeout(timer)); } - private async write( + private async requestStartWatch( req: BoardListWatchRequest, duplex: Duplex ): Promise { return new Promise((resolve, reject) => { - this.logger.info(`>>> Writing ${this.toJson(req)} to the stream...`); if ( !duplex.write(req, (err: Error | undefined) => { if (err) { - this.logger.error( - `<<< Error ocurred while writing to the stream.`, - err - ); reject(err); return; } }) ) { - duplex.once('drain', () => { - this.logger.info( - `<<< Board list watch request has been successfully written to the stream after the handling backpressure.` - ); - resolve(); - }); + duplex.once('drain', resolve); } else { - process.nextTick(() => { - this.logger.info( - `<<< Board list watch request has been successfully written to the stream.` - ); - resolve(); - }); + process.nextTick(resolve); } }); } @@ -302,7 +290,7 @@ export class BoardDiscovery this.notificationService.notifyAttachedBoardsDidChange(event); } }); - await this.write( + await this.requestStartWatch( new BoardListWatchRequest().setInstance(instance), wrapper.stream );