@@ -92,6 +92,19 @@ export const increment = (current?: number) => {
9292 return current !== undefined ? current + 1 : 1 ;
9393} ;
9494
95+ function triggersNextStep (
96+ updatedChannels : Set < string > ,
97+ triggerToNodes : Record < string , string [ ] > | undefined
98+ ) {
99+ if ( triggerToNodes == null ) return false ;
100+
101+ for ( const chan of updatedChannels ) {
102+ if ( triggerToNodes [ chan ] ) return true ;
103+ }
104+
105+ return false ;
106+ }
107+
95108// Avoids unnecessary double iteration
96109function maxChannelMapVersion (
97110 channelVersions : Record < string , number | string >
@@ -348,6 +361,7 @@ export function _applyWrites<Cc extends Record<string, BaseChannel>>(
348361 const channel = onlyChannels [ chan ] ;
349362 if ( channel . isAvailable ( ) && ! updatedChannels . has ( chan ) ) {
350363 const updated = channel . update ( [ ] ) ;
364+
351365 if ( updated && getNextVersion !== undefined ) {
352366 checkpoint . channel_versions [ chan ] = getNextVersion ( maxVersion ) ;
353367
@@ -359,12 +373,7 @@ export function _applyWrites<Cc extends Record<string, BaseChannel>>(
359373 }
360374
361375 // If this is (tentatively) the last superstep, notify all channels of finish
362- if (
363- bumpStep &&
364- ! Object . keys ( triggerToNodes ?? { } ) . some ( ( channel ) =>
365- updatedChannels . has ( channel )
366- )
367- ) {
376+ if ( bumpStep && ! triggersNextStep ( updatedChannels , triggerToNodes ) ) {
368377 for ( const chan in onlyChannels ) {
369378 if ( ! Object . prototype . hasOwnProperty . call ( onlyChannels , chan ) ) continue ;
370379
0 commit comments