15
15
*
16
16
*/
17
17
18
- use bevy:: prelude:: { Entity , Commands } ;
18
+ use bevy:: prelude:: { Entity , Commands , BuildChildren } ;
19
+
20
+ use std:: future:: Future ;
19
21
20
22
use crate :: {
21
23
Provider , UnusedTarget , StreamPack , Node , InputSlot , Output , StreamTargetMap ,
22
24
Buffer , BufferSettings , AddOperation , OperateBuffer , Scope , OperateScope ,
23
- ScopeSettings , BeginCancel ,
25
+ ScopeSettings , BeginCancel , ScopeEndpoints , IntoBlockingMap , IntoAsyncMap ,
24
26
} ;
25
27
26
28
pub ( crate ) mod connect;
@@ -58,7 +60,7 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
58
60
{
59
61
let source = self . commands . spawn ( ( ) ) . id ( ) ;
60
62
let target = self . commands . spawn ( UnusedTarget ) . id ( ) ;
61
- provider. connect ( source, target, self . commands ) ;
63
+ provider. connect ( Some ( self . scope ) , source, target, self . commands ) ;
62
64
63
65
let mut map = StreamTargetMap :: default ( ) ;
64
66
let ( bundle, streams) = <P :: Streams as StreamPack >:: spawn_node_streams (
@@ -72,6 +74,31 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
72
74
}
73
75
}
74
76
77
+ /// Create a [node](Node) that provides a [blocking map](crate::BlockingMap).
78
+ pub fn create_map_block < T , U > (
79
+ & mut self ,
80
+ f : impl FnMut ( T ) -> U + ' static + Send + Sync ,
81
+ ) -> Node < T , U , ( ) >
82
+ where
83
+ T : ' static + Send + Sync ,
84
+ U : ' static + Send + Sync ,
85
+ {
86
+ self . create_node ( f. into_blocking_map ( ) )
87
+ }
88
+
89
+ /// Create a [node](Node) that provides an [async map](crate::AsyncMap).
90
+ pub fn create_map_async < T , Task > (
91
+ & mut self ,
92
+ f : impl FnMut ( T ) -> Task + ' static + Send + Sync ,
93
+ ) -> Node < T , Task :: Output , ( ) >
94
+ where
95
+ T : ' static + Send + Sync ,
96
+ Task : Future + ' static + Send + Sync ,
97
+ Task :: Output : ' static + Send + Sync ,
98
+ {
99
+ self . create_node ( f. into_async_map ( ) )
100
+ }
101
+
75
102
/// Connect the output of one into the input slot of another node.
76
103
pub fn connect < T : ' static + Send + Sync > (
77
104
& mut self ,
@@ -94,6 +121,7 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
94
121
) -> Buffer < T > {
95
122
let source = self . commands . spawn ( ( ) ) . id ( ) ;
96
123
self . commands . add ( AddOperation :: new (
124
+ Some ( self . scope ) ,
97
125
source,
98
126
OperateBuffer :: < T > :: new ( settings) ,
99
127
) ) ;
@@ -160,8 +188,9 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
160
188
build,
161
189
) ;
162
190
163
- let begin_cancel = self . commands . spawn ( ( ) ) . id ( ) ;
191
+ let begin_cancel = self . commands . spawn ( ( ) ) . set_parent ( self . scope ) . id ( ) ;
164
192
self . commands . add ( AddOperation :: new (
193
+ None ,
165
194
begin_cancel,
166
195
BeginCancel :: < T > :: new ( self . scope , from_buffer. source , cancelling_scope_id) ,
167
196
) ) ;
@@ -190,13 +219,13 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
190
219
Response : ' static + Send + Sync ,
191
220
Streams : StreamPack ,
192
221
{
193
- let operation = OperateScope :: < Request , Response , Streams > :: new (
194
- scope_id, Some ( exit_scope) , settings, self . commands ,
222
+ let ScopeEndpoints {
223
+ terminal,
224
+ enter_scope,
225
+ finish_scope_cancel
226
+ } = OperateScope :: < Request , Response , Streams > :: add (
227
+ Some ( self . scope ( ) ) , scope_id, Some ( exit_scope) , settings, self . commands ,
195
228
) ;
196
- let enter_scope = operation. enter_scope ( ) ;
197
- let finish_scope_cancel = operation. finish_cancel ( ) ;
198
- let terminal = operation. terminal ( ) ;
199
- self . commands . add ( AddOperation :: new ( scope_id, operation) ) ;
200
229
201
230
let ( stream_in, stream_out) = Streams :: spawn_scope_streams (
202
231
scope_id,
0 commit comments