@@ -123,37 +123,7 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
123
123
Streams : StreamPack ,
124
124
{
125
125
let scope_id = self . commands . spawn ( ( ) ) . id ( ) ;
126
- let exit_scope = self . commands . spawn ( UnusedTarget ) . id ( ) ;
127
- let operation = OperateScope :: < Request , Response , Streams > :: new (
128
- scope_id, Some ( exit_scope) , settings, self . commands ,
129
- ) ;
130
- self . commands . add ( AddOperation :: new ( scope_id, operation) ) ;
131
-
132
- let ( stream_in, stream_out) = Streams :: spawn_scope_streams (
133
- scope_id,
134
- self . scope ,
135
- self . commands ,
136
- ) ;
137
-
138
- let mut builder = Builder {
139
- scope : scope_id,
140
- finish_scope_cancel : operation. finish_cancel ( ) ,
141
- commands : self . commands ,
142
- } ;
143
-
144
- let scope = Scope {
145
- input : Output :: new ( scope_id, operation. enter_scope ( ) ) ,
146
- terminate : InputSlot :: new ( scope_id, operation. terminal ( ) ) ,
147
- streams : stream_in,
148
- } ;
149
-
150
- build ( scope, & mut builder) ;
151
-
152
- Node {
153
- input : InputSlot :: new ( self . scope , scope_id) ,
154
- output : Output :: new ( self . scope , exit_scope) ,
155
- streams : stream_out,
156
- }
126
+ self . create_scope_impl ( scope_id, settings, build)
157
127
}
158
128
159
129
/// It is possible for a scope to be cancelled before it terminates. Even a
@@ -216,4 +186,49 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
216
186
pub fn commands ( & ' a mut self ) -> & ' a mut Commands < ' w , ' s > {
217
187
& mut self . commands
218
188
}
189
+
190
+ /// Used internally to create scopes in different ways.
191
+ pub ( crate ) fn create_scope_impl < Request , Response , Streams > (
192
+ & mut self ,
193
+ scope_id : Entity ,
194
+ settings : ScopeSettings ,
195
+ build : impl FnOnce ( Scope < Request , Response , Streams > , & mut Builder ) ,
196
+ ) -> Node < Request , Response , Streams >
197
+ where
198
+ Request : ' static + Send + Sync ,
199
+ Response : ' static + Send + Sync ,
200
+ Streams : StreamPack ,
201
+ {
202
+ let exit_scope = self . commands . spawn ( UnusedTarget ) . id ( ) ;
203
+ let operation = OperateScope :: < Request , Response , Streams > :: new (
204
+ scope_id, Some ( exit_scope) , settings, self . commands ,
205
+ ) ;
206
+ self . commands . add ( AddOperation :: new ( scope_id, operation) ) ;
207
+
208
+ let ( stream_in, stream_out) = Streams :: spawn_scope_streams (
209
+ scope_id,
210
+ self . scope ,
211
+ self . commands ,
212
+ ) ;
213
+
214
+ let mut builder = Builder {
215
+ scope : scope_id,
216
+ finish_scope_cancel : operation. finish_cancel ( ) ,
217
+ commands : self . commands ,
218
+ } ;
219
+
220
+ let scope = Scope {
221
+ input : Output :: new ( scope_id, operation. enter_scope ( ) ) ,
222
+ terminate : InputSlot :: new ( scope_id, operation. terminal ( ) ) ,
223
+ streams : stream_in,
224
+ } ;
225
+
226
+ build ( scope, & mut builder) ;
227
+
228
+ Node {
229
+ input : InputSlot :: new ( self . scope , scope_id) ,
230
+ output : Output :: new ( self . scope , exit_scope) ,
231
+ streams : stream_out,
232
+ }
233
+ }
219
234
}
0 commit comments