|
1 |
| -import type { ClientDuplexStream } from '@grpc/grpc-js'; |
| 1 | +import type { ClientReadableStream } from '@grpc/grpc-js'; |
2 | 2 | import {
|
3 | 3 | Disposable,
|
4 | 4 | DisposableCollection,
|
@@ -30,9 +30,9 @@ import type { Port as RpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/
|
30 | 30 | import { CoreClientAware } from './core-client-provider';
|
31 | 31 | import { ServiceError } from './service-error';
|
32 | 32 |
|
33 |
| -type Duplex = ClientDuplexStream<BoardListWatchRequest, BoardListWatchResponse>; |
| 33 | +type Stream = ClientReadableStream<BoardListWatchResponse>; |
34 | 34 | interface StreamWrapper extends Disposable {
|
35 |
| - readonly stream: Duplex; |
| 35 | + readonly stream: Stream; |
36 | 36 | readonly uuid: string; // For logging only
|
37 | 37 | }
|
38 | 38 |
|
@@ -121,34 +121,15 @@ export class BoardDiscovery
|
121 | 121 | return Disposable.create(() => clearTimeout(timer));
|
122 | 122 | }
|
123 | 123 |
|
124 |
| - private async requestStartWatch( |
125 |
| - req: BoardListWatchRequest, |
126 |
| - duplex: Duplex |
127 |
| - ): Promise<void> { |
128 |
| - return new Promise<void>((resolve, reject) => { |
129 |
| - if ( |
130 |
| - !duplex.write(req, (err: Error | undefined) => { |
131 |
| - if (err) { |
132 |
| - reject(err); |
133 |
| - return; |
134 |
| - } |
135 |
| - }) |
136 |
| - ) { |
137 |
| - duplex.once('drain', resolve); |
138 |
| - } else { |
139 |
| - process.nextTick(resolve); |
140 |
| - } |
141 |
| - }); |
142 |
| - } |
143 |
| - |
144 | 124 | private async createWrapper(
|
145 |
| - client: ArduinoCoreServiceClient |
| 125 | + client: ArduinoCoreServiceClient, |
| 126 | + req: BoardListWatchRequest |
146 | 127 | ): Promise<StreamWrapper> {
|
147 | 128 | if (this.wrapper) {
|
148 | 129 | throw new Error(`Duplex was already set.`);
|
149 | 130 | }
|
150 | 131 | const stream = client
|
151 |
| - .boardListWatch() |
| 132 | + .boardListWatch(req) |
152 | 133 | .on('end', () => {
|
153 | 134 | this.logger.info('received end');
|
154 | 135 | this.onStreamDidEndEmitter.fire();
|
@@ -202,14 +183,11 @@ export class BoardDiscovery
|
202 | 183 | this.watching = new Deferred();
|
203 | 184 | this.logger.info('start new deferred');
|
204 | 185 | const { client, instance } = await this.coreClient;
|
205 |
| - const wrapper = await this.createWrapper(client); |
206 |
| - wrapper.stream.on('data', (resp) => this.onBoardListWatchResponse(resp)); |
207 |
| - this.logger.info('start request start watch'); |
208 |
| - await this.requestStartWatch( |
209 |
| - new BoardListWatchRequest().setInstance(instance), |
210 |
| - wrapper.stream |
| 186 | + const wrapper = await this.createWrapper( |
| 187 | + client, |
| 188 | + new BoardListWatchRequest().setInstance(instance) |
211 | 189 | );
|
212 |
| - this.logger.info('start requested start watch'); |
| 190 | + wrapper.stream.on('data', (resp) => this.onBoardListWatchResponse(resp)); |
213 | 191 | this.watching.resolve();
|
214 | 192 | this.logger.info('start resolved watching');
|
215 | 193 | }
|
|
0 commit comments