@@ -22,7 +22,7 @@ use crate::{
22
22
Cancellation , Unreachability , InspectDisposals , execute_operation,
23
23
BufferSettings , Buffer , CancellableBundle , OperationRoster , ManageCancellation ,
24
24
OperationError , OperationCancel , Cancel , UnhandledErrors , check_reachability,
25
- Blocker , Stream , StreamTargetStorage ,
25
+ Blocker , Stream , StreamTargetStorage , StreamRequest ,
26
26
} ;
27
27
28
28
use backtrace:: Backtrace ;
@@ -1046,11 +1046,70 @@ pub(crate) struct ExitTarget {
1046
1046
pub ( crate ) blocker : Option < Blocker > ,
1047
1047
}
1048
1048
1049
- pub ( crate ) struct RedirectStream < T : Stream > {
1049
+ pub ( crate ) struct RedirectScopeStream < T : Stream > {
1050
1050
_ignore : std:: marker:: PhantomData < T > ,
1051
1051
}
1052
1052
1053
- impl < T : Stream > Operation for RedirectStream < T > {
1053
+ impl < T : Stream > RedirectScopeStream < T > {
1054
+ pub ( crate ) fn new ( ) -> Self {
1055
+ Self { _ignore : Default :: default ( ) }
1056
+ }
1057
+ }
1058
+
1059
+ impl < T : Stream > Operation for RedirectScopeStream < T > {
1060
+ fn setup ( self , OperationSetup { source, world } : OperationSetup ) -> OperationResult {
1061
+ world. entity_mut ( source) . insert (
1062
+ InputBundle :: < T > :: new ( ) ,
1063
+ ) ;
1064
+ Ok ( ( ) )
1065
+ }
1066
+
1067
+ fn execute (
1068
+ OperationRequest { source, world, roster } : OperationRequest ,
1069
+ ) -> OperationResult {
1070
+ let mut source_mut = world. get_entity_mut ( source) . or_broken ( ) ?;
1071
+ let Input { session : scoped_session, data } = source_mut. take_input :: < T > ( ) ?;
1072
+ let scope = source_mut. get :: < ScopeStorage > ( ) . or_broken ( ) ?. get ( ) ;
1073
+ let stream_target = world. get :: < StreamTargetStorage < T > > ( scope) . or_broken ( ) ?. get ( ) ;
1074
+ let parent_session = world. get :: < ParentSession > ( scoped_session) . or_broken ( ) ?. get ( ) ;
1075
+ data. send ( StreamRequest {
1076
+ source,
1077
+ session : parent_session,
1078
+ target : stream_target,
1079
+ world,
1080
+ roster
1081
+ } )
1082
+ }
1083
+
1084
+ fn is_reachable ( mut r : OperationReachability ) -> ReachabilityResult {
1085
+ if r. has_input :: < T > ( ) ? {
1086
+ return Ok ( true ) ;
1087
+ }
1088
+
1089
+ let scope = r. world . get :: < ScopeStorage > ( r. source ) . or_broken ( ) ?. get ( ) ;
1090
+ r. check_upstream ( scope)
1091
+
1092
+ // TODO(@mxgrey): Consider whether we can/should identify more
1093
+ // specifically whether the current state of the scope would be able to
1094
+ // reach this specific stream.
1095
+ }
1096
+
1097
+ fn cleanup ( mut clean : OperationCleanup ) -> OperationResult {
1098
+ clean. cleanup_inputs :: < T > ( )
1099
+ }
1100
+ }
1101
+
1102
+ pub ( crate ) struct RedirectWorkflowStream < T : Stream > {
1103
+ _ignore : std:: marker:: PhantomData < T > ,
1104
+ }
1105
+
1106
+ impl < T : Stream > RedirectWorkflowStream < T > {
1107
+ pub ( crate ) fn new ( ) -> Self {
1108
+ Self { _ignore : Default :: default ( ) }
1109
+ }
1110
+ }
1111
+
1112
+ impl < T : Stream > Operation for RedirectWorkflowStream < T > {
1054
1113
fn setup ( self , OperationSetup { source, world } : OperationSetup ) -> OperationResult {
1055
1114
world. entity_mut ( source) . insert (
1056
1115
InputBundle :: < T > :: new ( ) ,
@@ -1062,10 +1121,10 @@ impl<T: Stream> Operation for RedirectStream<T> {
1062
1121
OperationRequest { source, world, roster } : OperationRequest ,
1063
1122
) -> OperationResult {
1064
1123
let mut source_mut = world. get_entity_mut ( source) . or_broken ( ) ?;
1065
- let Input { session, data } = source_mut. take_input :: < T > ( ) ?;
1124
+ let Input { session : scoped_session , data } = source_mut. take_input :: < T > ( ) ?;
1066
1125
let scope = source_mut. get :: < ScopeStorage > ( ) . or_broken ( ) ?. get ( ) ;
1067
1126
let exit = world. get :: < ExitTargetStorage > ( scope) . or_broken ( ) ?
1068
- . map . get ( & session )
1127
+ . map . get ( & scoped_session )
1069
1128
// If the map does not have this session in it, that should simply
1070
1129
// mean that the workflow has terminated, so we should discard this
1071
1130
// stream data.
@@ -1078,9 +1137,13 @@ impl<T: Stream> Operation for RedirectStream<T> {
1078
1137
let stream_target = world. get :: < StreamTargetStorage < T > > ( exit_source)
1079
1138
. or_broken ( ) ?. get ( ) ;
1080
1139
1081
- world. get_entity_mut ( stream_target) . or_broken ( ) ?. give_input (
1082
- parent_session, data, roster,
1083
- )
1140
+ data. send ( StreamRequest {
1141
+ source,
1142
+ session : parent_session,
1143
+ target : stream_target,
1144
+ world,
1145
+ roster,
1146
+ } )
1084
1147
}
1085
1148
1086
1149
fn is_reachable ( mut r : OperationReachability ) -> ReachabilityResult {
0 commit comments