@@ -220,18 +220,18 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
220
220
/// If you want to connect to the stream outputs, use
221
221
/// [`Self::then_scope_node`] instead.
222
222
#[ must_use]
223
- pub fn then_scope < Response , Streams > (
223
+ pub fn then_scope < Response , Streams , Settings > (
224
224
self ,
225
- settings : ScopeSettings ,
226
- build : impl FnOnce ( Scope < T , Response , Streams > , & mut Builder ) ,
225
+ build : impl FnOnce ( Scope < T , Response , Streams > , & mut Builder ) -> Settings ,
227
226
) -> Chain < ' w , ' s , ' a , ' b , Response >
228
227
where
229
228
Response : ' static + Send + Sync ,
230
229
Streams : StreamPack ,
230
+ Settings : Into < ScopeSettings > ,
231
231
{
232
232
let exit_scope = self . builder . commands . spawn ( UnusedTarget ) . id ( ) ;
233
- self . builder . create_scope_impl :: < T , Response , Streams > (
234
- self . target , exit_scope, settings , build,
233
+ self . builder . create_scope_impl :: < T , Response , Streams , Settings > (
234
+ self . target , exit_scope, build,
235
235
) . output . chain ( self . builder )
236
236
}
237
237
@@ -241,31 +241,32 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
241
241
///
242
242
/// Unlike `then_scope`, this function can infer the types for the generics
243
243
/// so you don't need to explicitly specify them.
244
- pub fn then_io_scope < Response > (
244
+ pub fn then_io_scope < Response , Settings > (
245
245
self ,
246
- build : impl FnOnce ( Scope < T , Response , ( ) > , & mut Builder ) ,
246
+ build : impl FnOnce ( Scope < T , Response , ( ) > , & mut Builder ) -> Settings ,
247
247
) -> Chain < ' w , ' s , ' a , ' b , Response >
248
248
where
249
249
Response : ' static + Send + Sync ,
250
+ Settings : Into < ScopeSettings > ,
250
251
{
251
- self . then_scope ( ScopeSettings :: default ( ) , build)
252
+ self . then_scope ( build)
252
253
}
253
254
254
255
/// From the current target in the chain, build a [scoped](Scope) workflow
255
256
/// and then get back a node that represents that scoped workflow.
256
257
#[ must_use]
257
- pub fn then_scope_node < Response , Streams > (
258
+ pub fn then_scope_node < Response , Streams , Settings > (
258
259
self ,
259
- settings : ScopeSettings ,
260
- build : impl FnOnce ( Scope < T , Response , Streams > , & mut Builder ) ,
260
+ build : impl FnOnce ( Scope < T , Response , Streams > , & mut Builder ) -> Settings ,
261
261
) -> Node < T , Response , Streams >
262
262
where
263
263
Response : ' static + Send + Sync ,
264
264
Streams : StreamPack ,
265
+ Settings : Into < ScopeSettings > ,
265
266
{
266
267
let exit_scope = self . builder . commands . spawn ( UnusedTarget ) . id ( ) ;
267
- self . builder . create_scope_impl :: < T , Response , Streams > (
268
- self . target , exit_scope, settings , build,
268
+ self . builder . create_scope_impl :: < T , Response , Streams , Settings > (
269
+ self . target , exit_scope, build,
269
270
)
270
271
}
271
272
@@ -275,14 +276,15 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
275
276
///
276
277
/// Unlike `then_scope_node`, this function can infer the types for the
277
278
/// generics so you don't need to explicitly specify them.
278
- pub fn then_io_scope_node < Response > (
279
+ pub fn then_io_scope_node < Response , Settings > (
279
280
self ,
280
- build : impl FnOnce ( Scope < T , Response , ( ) > , & mut Builder ) ,
281
+ build : impl FnOnce ( Scope < T , Response , ( ) > , & mut Builder ) -> Settings ,
281
282
) -> Node < T , Response , ( ) >
282
283
where
283
284
Response : ' static + Send + Sync ,
285
+ Settings : Into < ScopeSettings > ,
284
286
{
285
- self . then_scope_node ( ScopeSettings :: default ( ) , build)
287
+ self . then_scope_node ( build)
286
288
}
287
289
288
290
/// Apply a [`Provider`] that filters the response by returning an [`Option`].
@@ -499,14 +501,21 @@ where
499
501
/// that trait, then you can use [`Self::cancel_on_quiet_err`] instead.
500
502
///
501
503
/// ```
502
- /// use bevy_impulse::{*, testing::*};
504
+ /// use crate::{*, testing::*};
505
+ ///
503
506
/// let mut context = TestingContext::minimal_plugins();
504
- /// let mut promise = context.build(|commands| {
507
+ ///
508
+ /// let workflow = context.spawn_io_workflow(|scope, builder| {
509
+ /// scope.input.chain(builder)
510
+ /// .map_block(produce_err)
511
+ /// .cancel_on_err()
512
+ /// .connect(scope.terminate);
513
+ /// });
514
+ ///
515
+ /// let mut promise = context.command(|commands| {
505
516
/// commands
506
- /// .provide("hello")
507
- /// .map_block(produce_err)
508
- /// .cancel_on_err()
509
- /// .take()
517
+ /// .request("hello", workflow)
518
+ /// .take_response()
510
519
/// });
511
520
///
512
521
/// context.run_while_pending(&mut promise);
@@ -703,49 +712,41 @@ mod tests {
703
712
fn test_join ( ) {
704
713
let mut context = TestingContext :: minimal_plugins ( ) ;
705
714
706
- let workflow = context. build_io_workflow ( |scope, builder| {
715
+ let workflow = context. spawn_io_workflow ( |scope, builder| {
707
716
scope. input . chain ( builder)
708
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
709
717
// (2.0, 2.0)
710
718
. unzip_build ( (
711
719
|chain : Chain < f64 > | chain
712
720
// 2.0
713
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
714
721
. map_block ( |value|
715
722
WaitRequest {
716
723
duration : Duration :: from_secs_f64 ( value/100.0 ) ,
717
724
value,
718
725
}
719
726
)
720
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
721
727
. map_async ( wait)
722
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
723
728
// 2.0
724
729
. output ( ) ,
725
730
|chain : Chain < f64 > | chain
726
731
// 2.0
727
732
. map_block ( |value| 2.0 * value)
728
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
729
733
// 4.0
730
734
. output ( ) ,
731
735
) )
732
736
. join ( builder)
733
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
734
737
// (2.0, 4.0)
735
738
. map_block ( add)
736
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
737
739
// 6.0
738
740
. connect ( scope. terminate ) ;
739
741
} ) ;
740
742
741
- let mut promise = context. build ( |commands|
743
+ let mut promise = context. command ( |commands|
742
744
commands
743
745
. request ( ( 2.0 , 2.0 ) , workflow)
744
746
. take_response ( )
745
747
) ;
746
748
747
749
context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
748
- dbg ! ( promise. peek( ) ) ;
749
750
assert ! ( promise. peek( ) . available( ) . is_some_and( |value| * value == 6.0 ) ) ;
750
751
assert ! ( context. no_unhandled_errors( ) ) ;
751
752
}
@@ -754,12 +755,12 @@ mod tests {
754
755
fn test_race ( ) {
755
756
let mut context = TestingContext :: minimal_plugins ( ) ;
756
757
757
- let workflow = context. build_io_workflow ( |scope, builder| {
758
+ let workflow = context. spawn_io_workflow ( |scope, builder| {
758
759
scope. input . chain ( builder)
759
760
// (2.0, 2.0)
760
761
. map_block ( add)
761
762
// 4.0
762
- . then_scope :: < _ , ( ) > ( ScopeSettings :: default ( ) , |scope, builder| {
763
+ . then_io_scope ( |scope, builder| {
763
764
scope. input . chain ( builder)
764
765
// 4.0
765
766
. fork_clone ( (
@@ -794,7 +795,7 @@ mod tests {
794
795
. connect ( scope. terminate ) ;
795
796
} ) ;
796
797
797
- let mut promise = context. build ( |commands|
798
+ let mut promise = context. command ( |commands|
798
799
commands
799
800
. request ( ( 2.0 , 2.0 ) , workflow)
800
801
. take_response ( )
@@ -814,11 +815,11 @@ mod tests {
814
815
fn test_unzip ( ) {
815
816
let mut context = TestingContext :: minimal_plugins ( ) ;
816
817
817
- let workflow = context. build_io_workflow ( |scope, builder| {
818
+ let workflow = context. spawn_io_workflow ( |scope, builder| {
818
819
scope. input . chain ( builder)
819
820
. map_block ( add)
820
821
. map_block ( |v| ( v, 2.0 * v) )
821
- . then_scope :: < _ , ( ) > ( ScopeSettings :: default ( ) , |scope, builder| {
822
+ . then_io_scope ( |scope, builder| {
822
823
scope. input . chain ( builder)
823
824
. unzip_build ( (
824
825
|chain : Chain < f64 > | {
@@ -844,7 +845,7 @@ mod tests {
844
845
} ) ;
845
846
846
847
847
- let mut promise = context. build ( |commands| {
848
+ let mut promise = context. command ( |commands| {
848
849
commands
849
850
. request ( ( 2.0 , 3.0 ) , workflow)
850
851
. take_response ( )
@@ -859,38 +860,28 @@ mod tests {
859
860
fn test_cancel_on_special_case ( ) {
860
861
let mut context = TestingContext :: minimal_plugins ( ) ;
861
862
862
- dbg ! ( ) ;
863
- let workflow = context. build_io_workflow ( |scope, builder| {
863
+ let workflow = context. spawn_io_workflow ( |scope, builder| {
864
864
scope. input . chain ( builder)
865
865
. map_block ( duplicate)
866
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
867
866
. map_block ( add)
868
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
869
867
. map_block ( produce_none)
870
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
871
868
. cancel_on_none ( )
872
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
873
869
. map_block ( duplicate)
874
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
875
870
. map_block ( add)
876
- . map ( print_debug ( format ! ( "{}" , line!( ) ) ) )
877
871
. connect ( scope. terminate ) ;
878
872
} ) ;
879
873
880
- dbg ! ( ) ;
881
- let mut promise = context. build ( |commands| {
874
+ let mut promise = context. command ( |commands| {
882
875
commands
883
876
. request ( 2.0 , workflow)
884
877
. take_response ( )
885
878
} ) ;
886
879
887
- dbg ! ( ) ;
888
880
context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
889
- dbg ! ( context. get_unhandled_errors( ) ) ;
890
881
assert ! ( promise. peek( ) . is_cancelled( ) ) ;
891
882
assert ! ( context. no_unhandled_errors( ) ) ;
892
883
893
- let workflow = context. build_io_workflow ( |scope, builder| {
884
+ let workflow = context. spawn_io_workflow ( |scope, builder| {
894
885
scope. input . chain ( builder)
895
886
. map_block ( duplicate)
896
887
. map_block ( add)
@@ -901,7 +892,7 @@ mod tests {
901
892
. connect ( scope. terminate ) ;
902
893
} ) ;
903
894
904
- let mut promise = context. build ( |commands| {
895
+ let mut promise = context. command ( |commands| {
905
896
commands
906
897
. request ( 2.0 , workflow)
907
898
. take_response ( )
@@ -916,7 +907,7 @@ mod tests {
916
907
fn test_disposal ( ) {
917
908
let mut context = TestingContext :: minimal_plugins ( ) ;
918
909
919
- let workflow = context. build_io_workflow ( |scope, builder| {
910
+ let workflow = context. spawn_io_workflow ( |scope, builder| {
920
911
scope. input . chain ( builder)
921
912
. map_block ( duplicate)
922
913
. map_block ( add)
@@ -927,14 +918,13 @@ mod tests {
927
918
. connect ( scope. terminate ) ;
928
919
} ) ;
929
920
930
- let mut promise = context. build ( |commands| {
921
+ let mut promise = context. command ( |commands| {
931
922
commands
932
923
. request ( 2.0 , workflow)
933
924
. take_response ( )
934
925
} ) ;
935
926
936
927
context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
937
- dbg ! ( promise. peek( ) ) ;
938
928
assert ! ( promise. peek( ) . is_cancelled( ) ) ;
939
929
assert ! ( context. no_unhandled_errors( ) ) ;
940
930
}
0 commit comments