@@ -15,10 +15,11 @@ import moveHubZip from '@pybricks/firmware/build/movehub.zip';
1515import technicHubZip from '@pybricks/firmware/build/technichub.zip' ;
1616import { WebDFU } from 'dfu' ;
1717import { AnyAction } from 'redux' ;
18- import { channel , eventChannel } from 'redux-saga' ;
18+ import { eventChannel } from 'redux-saga' ;
1919import { ActionPattern } from 'redux-saga/effects' ;
2020import {
2121 SagaGenerator ,
22+ actionChannel ,
2223 all ,
2324 call ,
2425 cancel ,
@@ -1140,24 +1141,10 @@ function* handleFlashEV3(action: ReturnType<typeof firmwareFlashEV3>): Generator
11401141 payload ?: Uint8Array ,
11411142 ) : SagaGenerator < [ DataView | undefined , Error | undefined ] > {
11421143 // Create a channel that buffers the actions
1143- const replyChannel = yield * call (
1144- channel < ReturnType < typeof firmwareDidReceiveEV3Reply > > ,
1144+ const replyChannel = yield * actionChannel (
1145+ firmwareDidReceiveEV3Reply . when ( ( a ) => a . replyCommand === command ) ,
11451146 ) ;
11461147
1147- // Create a task that forwards matching actions to our channel
1148- // Sending the command and setting up the listener are not atomic,
1149- // so we might receive the reply before we start listening. To handle
1150- // this, we keep listening until we find the matching reply.
1151- const forwardTask = yield * fork ( function * ( ) {
1152- while ( true ) {
1153- const action = yield * take ( firmwareDidReceiveEV3Reply ) ;
1154- if ( action . replyCommand === command ) {
1155- yield * put ( replyChannel , action ) ;
1156- break ; // Stop after finding the matching reply
1157- }
1158- }
1159- } ) ;
1160-
11611148 // Send the command
11621149 const dataBuffer = new Uint8Array ( ( payload ?. byteLength ?? 0 ) + 6 ) ;
11631150 const data = new DataView ( dataBuffer . buffer ) ;
@@ -1206,7 +1193,6 @@ function* handleFlashEV3(action: ReturnType<typeof firmwareFlashEV3>): Generator
12061193 }
12071194
12081195 // Clean up
1209- yield * cancel ( forwardTask ) ;
12101196 yield * call ( ( ) => replyChannel . close ( ) ) ;
12111197
12121198 return [ new DataView ( reply . payload ) , undefined ] ;
0 commit comments