@@ -33,6 +33,7 @@ import {
3333 BoardDetailsRequest ,
3434 BoardDetailsResponse ,
3535 BoardListAllRequest ,
36+ BoardListAllResponse ,
3637 BoardSearchRequest ,
3738} from './cli-protocol/cc/arduino/cli/commands/v1/board_pb' ;
3839import {
@@ -200,37 +201,28 @@ export class BoardsServiceImpl
200201 const req = new BoardSearchRequest ( ) ;
201202 req . setSearchArgs ( query || '' ) ;
202203 req . setInstance ( instance ) ;
203- const boards = await new Promise < BoardWithPackage [ ] > ( ( resolve , reject ) => {
204- client . boardSearch ( req , ( error , resp ) => {
205- if ( error ) {
206- reject ( error ) ;
207- return ;
208- }
209- const boards : Array < BoardWithPackage > = [ ] ;
210- for ( const board of resp . getBoardsList ( ) ) {
211- const platform = board . getPlatform ( ) ;
212- if ( platform ) {
213- boards . push ( {
214- name : board . getName ( ) ,
215- fqbn : board . getFqbn ( ) ,
216- packageId : platform . getId ( ) ,
217- packageName : platform . getName ( ) ,
218- manuallyInstalled : platform . getManuallyInstalled ( ) ,
219- } ) ;
220- }
221- }
222- resolve ( boards ) ;
223- } ) ;
224- } ) ;
225- return boards ;
204+ return this . handleListBoards ( client . boardSearch . bind ( client ) , req ) ;
226205 }
227206
228207 async getInstalledBoards ( ) : Promise < BoardWithPackage [ ] > {
229208 const { instance, client } = await this . coreClient ;
230209 const req = new BoardListAllRequest ( ) ;
231210 req . setInstance ( instance ) ;
211+ return this . handleListBoards ( client . boardListAll . bind ( client ) , req ) ;
212+ }
213+ 214+ async handleListBoards (
215+ getBoards : (
216+ request : BoardListAllRequest | BoardSearchRequest ,
217+ callback : (
218+ error : ServiceError | null ,
219+ response : BoardListAllResponse
220+ ) => void
221+ ) => void ,
222+ request : BoardListAllRequest | BoardSearchRequest
223+ ) : Promise < BoardWithPackage [ ] > {
232224 const boards = await new Promise < BoardWithPackage [ ] > ( ( resolve , reject ) => {
233- client . boardListAll ( req , ( error , resp ) => {
225+ getBoards ( request , ( error , resp ) => {
234226 if ( error ) {
235227 reject ( error ) ;
236228 return ;
0 commit comments