@@ -46,6 +46,9 @@ export tr_failure;
46
46
export get_task;
47
47
export spawn;
48
48
export spawn_joinable;
49
+ export spawn_connected;
50
+ export connected_fn;
51
+ export connected_task;
49
52
50
53
#[ abi = "rust-intrinsic" ]
51
54
native mod rusti {
@@ -190,27 +193,58 @@ tag task_notification {
190
193
}
191
194
192
195
/*
193
- type connected_fn<ToCh, FrCh> = sendfn(comm::chan<FrCh>, comm::port<ToCh>);
196
+ Type: connected_fn
197
+
198
+ The prototype for a connected child task function. Such a function will be
199
+ supplied with a channel to send messages to the parent and a port to receive
200
+ messages from the parent. The type parameter `ToCh` is the type for messages
201
+ sent from the parent to the child and `FrCh` is the type for messages sent
202
+ from the child to the parent. */
203
+ type connected_fn < ToCh , FrCh > = sendfn ( comm:: port < ToCh > , comm:: chan < FrCh > ) ;
204
+
205
+ /*
206
+ Type: connected_fn
207
+
208
+ The result type of <spawn_connected>
209
+ */
194
210
type connected_task < ToCh , FrCh > = {
195
- port : comm::port<FrCh>,
196
- chan : comm::chan<ToCh>,
211
+ from_child : comm:: port < FrCh > ,
212
+ to_child : comm:: chan < ToCh > ,
197
213
task : task
198
214
} ;
215
+
216
+ /*
217
+ Function: spawn_connected
218
+
219
+ Spawns a child task along with a port/channel for exchanging messages
220
+ with the parent task. The type `ToCh` represents messages sent to the child
221
+ and `FrCh` messages received from the child.
222
+
223
+ Parameters:
224
+
225
+ f - the child function to execute
226
+
227
+ Returns:
228
+
229
+ The new child task along with the port to receive messages and the channel
230
+ to send messages.
231
+ */
199
232
fn spawn_connected < ToCh : send , FrCh : send > ( f : connected_fn < ToCh , FrCh > )
200
- -> connected_fn {
201
- let from_child_port = comm::port<FrCh>();
233
+ -> connected_task < ToCh , FrCh > {
234
+ let from_child_port = comm:: port :: < FrCh > ( ) ;
202
235
let from_child_chan = comm:: chan ( from_child_port) ;
203
- let get_to_child_port = comm::port<comm::chan<ToCh>>();
204
- let get_to_child_chan = comm::chan(to_child_port );
236
+ let get_to_child_port = comm:: port :: < comm:: chan < ToCh > > ( ) ;
237
+ let get_to_child_chan = comm:: chan ( get_to_child_port ) ;
205
238
let child_task = spawn ( sendfn[ move f] ( ) {
206
- let to_child_port = comm::port<ToCh>();
207
- comm::send(get_to_child_chan, to_child_port);
208
- f(from_child_chan, to_child_port );
239
+ let to_child_port = comm:: port :: < ToCh > ( ) ;
240
+ comm:: send ( get_to_child_chan, comm :: chan ( to_child_port) ) ;
241
+ f ( to_child_port , from_child_chan ) ;
209
242
} ) ;
210
- let to_child_chan = comm::recv(get_out);
211
- ret {port: from_child_port, chan: to_child_chan, task: child_task};
243
+ let to_child_chan = comm:: recv ( get_to_child_port) ;
244
+ ret { from_child : from_child_port,
245
+ to_child : to_child_chan,
246
+ task : child_task} ;
212
247
}
213
- */
214
248
215
249
/* Section: Operations */
216
250
0 commit comments