@@ -574,7 +574,7 @@ To add a new serial device, you must add an object to
574
574
}
575
575
576
576
// Asynchronously call 'getPorts' on all devices and map results back as a series of promises
577
- Promise . allSettled (
577
+ Promise . all (
578
578
devices . map ( ( device ) =>
579
579
new Promise ( ( resolve ) => device . getPorts ( resolve ) ) . then (
580
580
( devicePorts , instantPorts ) => ( {
@@ -591,27 +591,15 @@ To add a new serial device, you must add an object to
591
591
} )
592
592
)
593
593
)
594
- ) . then ( ( devicePromises ) => {
595
- // Reduce the responses to only promises that were fulfilled
596
- const successfulPorts = devicePromises . reduce ( ( acc , promise ) => {
597
- if ( promise . status === "fulfilled" ) acc . push ( promise . value ) ;
598
- return acc ;
599
- } , [ ] ) ;
600
-
601
- portToDevice = devicePromises . reduce ( ( acc , promise ) => {
602
- if ( promise . status === "fulfilled" )
603
- promise . value . value . forEach (
604
- ( port ) => ( acc [ port . path ] = promise . value . device )
605
- ) ;
606
-
594
+ ) . then ( ( results ) => {
595
+ portToDevice = results . reduce ( ( acc , promise ) => {
596
+ promise . value . forEach ( ( port ) => ( acc [ port . path ] = promise . device ) ) ;
607
597
return acc ;
608
598
} , { } ) ;
609
599
610
600
callback (
611
- successfulPorts
612
- . map ( ( val ) => val . value )
613
- . reduce ( ( acc , port ) => acc . concat ( port ) , [ ] ) ,
614
- successfulPorts . some ( ( val ) => val . shouldCallAgain )
601
+ results . flatMap ( ( result ) => result . value ) ,
602
+ results . some ( ( result ) => result . shouldCallAgain )
615
603
) ;
616
604
} ) ;
617
605
} ;
0 commit comments