Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta authored and kittaakos committed Jul 14, 2022
1 parent 8134444 commit aea550f
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions arduino-ide-extension/src/node/board-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export class BoardDiscovery
stop(): Promise<void> {
this.logger.info('>>> Stopping boards watcher...');
return new Promise<void>((resolve, reject) => {
const timeout = this.timeout(BoardDiscovery.StopWatchTimeout, reject);
const timeout = this.createTimeout(
BoardDiscovery.StopWatchTimeout,
reject
);
const toDispose = new DisposableCollection();
toDispose.pushAll([
timeout,
Expand All @@ -107,7 +110,7 @@ export class BoardDiscovery
});
}

private timeout(
private createTimeout(
after: number,
onTimeout: (error: Error) => void
): Disposable {
Expand All @@ -118,37 +121,22 @@ export class BoardDiscovery
return Disposable.create(() => clearTimeout(timer));
}

private async write(
private async requestStartWatch(
req: BoardListWatchRequest,
duplex: Duplex
): Promise<void> {
return new Promise<void>((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);
}
});
}
Expand Down Expand Up @@ -302,7 +290,7 @@ export class BoardDiscovery
this.notificationService.notifyAttachedBoardsDidChange(event);
}
});
await this.write(
await this.requestStartWatch(
new BoardListWatchRequest().setInstance(instance),
wrapper.stream
);
Expand Down

0 comments on commit aea550f

Please sign in to comment.