@@ -532,7 +532,12 @@ impl<T: 'static + Send + Sync, const N: usize> Splittable for [T; N] {
532
532
533
533
fn next ( key : & Option < Self :: Key > ) -> Option < Self :: Key > {
534
534
// Static arrays have a firm limit of N
535
- SplitAsList :: < Self > :: next ( key) . take_if ( |key| Self :: validate ( key) )
535
+ let mut key = SplitAsList :: < Self > :: next ( key) ;
536
+ if key. map_or ( false , |key| Self :: validate ( & key) ) {
537
+ key. take ( )
538
+ } else {
539
+ None
540
+ }
536
541
}
537
542
538
543
fn split ( self , dispatcher : SplitDispatcher < ' _ , Self :: Key , Self :: Item > ) -> OperationResult {
@@ -936,4 +941,49 @@ mod tests {
936
941
assert_eq ! ( result[ "fib" ] , input_map[ "fib" ] ) ;
937
942
assert_eq ! ( result[ "dib" ] , input_map[ "dib" ] ) ;
938
943
}
944
+
945
+ #[ test]
946
+ fn test_array_split_limit ( ) {
947
+ let mut context = TestingContext :: minimal_plugins ( ) ;
948
+
949
+ let workflow = context. spawn_io_workflow ( |scope, builder| {
950
+ scope. input . chain ( builder) . split ( |split| {
951
+ let err = split
952
+ . next_branch ( |_, chain| {
953
+ chain. value ( ) . connect ( scope. terminate ) ;
954
+ } )
955
+ . unwrap ( )
956
+ . next_branch ( |_, chain| {
957
+ chain. value ( ) . connect ( scope. terminate ) ;
958
+ } )
959
+ . unwrap ( )
960
+ . next_branch ( |_, chain| {
961
+ chain. value ( ) . connect ( scope. terminate ) ;
962
+ } )
963
+ . unwrap ( )
964
+ . next_branch ( |_, chain| {
965
+ chain. value ( ) . connect ( scope. terminate ) ;
966
+ } )
967
+ . unwrap ( )
968
+ // This last one should fail because it should exceed the
969
+ // array limit
970
+ . next_branch ( |_, chain| {
971
+ chain. value ( ) . connect ( scope. terminate ) ;
972
+ } ) ;
973
+
974
+ assert ! ( matches!( err, Err ( _) ) ) ;
975
+ } )
976
+ } ) ;
977
+
978
+ let mut promise =
979
+ context. command ( |commands| commands. request ( [ 1 , 2 , 3 , 4 ] , workflow) . take_response ( ) ) ;
980
+
981
+ context. run_with_conditions ( & mut promise, 1 ) ;
982
+ assert ! ( context. no_unhandled_errors( ) ) ;
983
+
984
+ let result = promise. take ( ) . available ( ) . unwrap ( ) ;
985
+ // All the values in the array are racing to finish, but the first value
986
+ // should finish first since it will naturally get queued first.
987
+ assert_eq ! ( result, 1 ) ;
988
+ }
939
989
}
0 commit comments