@@ -453,7 +453,7 @@ where
453
453
) -> Chain < ' w , ' s , ' a , ' b , T > {
454
454
Chain :: < Result < T , E > > :: new (
455
455
self . target , self . builder ,
456
- ) . branch_result_zip (
456
+ ) . fork_result (
457
457
|chain| chain. output ( ) ,
458
458
build_err,
459
459
) . 0 . chain ( self . builder )
@@ -466,8 +466,7 @@ where
466
466
///
467
467
/// The outputs of both builder functions will be zipped as the return value
468
468
/// of this function.
469
- #[ must_use]
470
- pub fn branch_result_zip < U , V > (
469
+ pub fn fork_result < U , V > (
471
470
self ,
472
471
build_ok : impl FnOnce ( Chain < T > ) -> U ,
473
472
build_err : impl FnOnce ( Chain < E > ) -> V ,
@@ -844,7 +843,6 @@ mod tests {
844
843
. connect ( scope. terminate ) ;
845
844
} ) ;
846
845
847
-
848
846
let mut promise = context. command ( |commands| {
849
847
commands
850
848
. request ( ( 2.0 , 3.0 ) , workflow)
@@ -927,5 +925,45 @@ mod tests {
927
925
context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
928
926
assert ! ( promise. peek( ) . is_cancelled( ) ) ;
929
927
assert ! ( context. no_unhandled_errors( ) ) ;
928
+
929
+ let workflow = context. spawn_io_workflow (
930
+ |scope : Scope < Result < f64 , Result < f64 , TestError > > , f64 > , builder| {
931
+ scope. input . chain ( builder)
932
+ . fork_result (
933
+ |chain| chain. connect ( scope. terminate ) ,
934
+ |chain|
935
+ chain. dispose_on_err ( ) . connect ( scope. terminate )
936
+ ) ;
937
+ } ) ;
938
+
939
+ let mut promise = context. command ( |commands| {
940
+ commands
941
+ . request ( Ok ( 1.0 ) , workflow)
942
+ . take_response ( )
943
+ } ) ;
944
+
945
+ context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
946
+ assert ! ( promise. peek( ) . available( ) . is_some_and( |v| * v == 1.0 ) ) ;
947
+ assert ! ( context. no_unhandled_errors( ) ) ;
948
+
949
+ let mut promise = context. command ( |commands| {
950
+ commands
951
+ . request ( Err ( Ok ( 5.0 ) ) , workflow)
952
+ . take_response ( )
953
+ } ) ;
954
+
955
+ context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
956
+ assert ! ( promise. peek( ) . available( ) . is_some_and( |v| * v == 5.0 ) ) ;
957
+ assert ! ( context. no_unhandled_errors( ) ) ;
958
+
959
+ let mut promise = context. command ( |commands| {
960
+ commands
961
+ . request ( Err ( Err ( TestError ) ) , workflow)
962
+ . take_response ( )
963
+ } ) ;
964
+
965
+ context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
966
+ assert ! ( promise. peek( ) . is_cancelled( ) ) ;
967
+ assert ! ( context. no_unhandled_errors( ) ) ;
930
968
}
931
969
}
0 commit comments