Skip to content

Commit 106385c

Browse files
committed
make spawned fn copy mode so that bare fns can be used
1 parent 7d3f892 commit 106385c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/libcore/task.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Returns:
110110
111111
A handle to the new task
112112
*/
113-
fn spawn(-f: sendfn()) -> task {
113+
fn spawn(+f: sendfn()) -> task {
114114
spawn_inner(f, none)
115115
}
116116

@@ -139,7 +139,7 @@ A task that sends notification upon termination
139139
*/
140140
type joinable_task = (task, comm::port<task_notification>);
141141

142-
fn spawn_joinable(-f: sendfn()) -> joinable_task {
142+
fn spawn_joinable(+f: sendfn()) -> joinable_task {
143143
let notify_port = comm::port();
144144
let notify_chan = comm::chan(notify_port);
145145
let task = spawn_inner(f, some(notify_chan));
@@ -189,6 +189,29 @@ tag task_notification {
189189
exit(task, task_result);
190190
}
191191

192+
/*
193+
type connected_fn<ToCh, FrCh> = sendfn(comm::chan<FrCh>, comm::port<ToCh>);
194+
type connected_task<ToCh, FrCh> = {
195+
port: comm::port<FrCh>,
196+
chan: comm::chan<ToCh>,
197+
task: task
198+
};
199+
fn spawn_connected<ToCh:send, FrCh:send>(f: connected_fn<ToCh, FrCh>)
200+
-> connected_fn {
201+
let from_child_port = comm::port<FrCh>();
202+
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);
205+
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);
209+
});
210+
let to_child_chan = comm::recv(get_out);
211+
ret {port: from_child_port, chan: to_child_chan, task: child_task};
212+
}
213+
*/
214+
192215
/* Section: Operations */
193216

194217
/*
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// error-pattern:Ensure that the child task runs by failing
2+
3+
fn main() {
4+
// the purpose of this test is to make sure that task::spawn()
5+
// works when provided with a bare function:
6+
task::spawn(startfn);
7+
}
8+
9+
fn startfn() {
10+
assert str::is_empty("Ensure that the child task runs by failing");
11+
}

0 commit comments

Comments
 (0)