提交 106385cb 编写于 作者: N Niko Matsakis

make spawned fn copy mode so that bare fns can be used

上级 7d3f892f
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
A handle to the new task A handle to the new task
*/ */
fn spawn(-f: sendfn()) -> task { fn spawn(+f: sendfn()) -> task {
spawn_inner(f, none) spawn_inner(f, none)
} }
...@@ -139,7 +139,7 @@ fn spawn_inner(-f: sendfn(), ...@@ -139,7 +139,7 @@ fn spawn_inner(-f: sendfn(),
*/ */
type joinable_task = (task, comm::port<task_notification>); type joinable_task = (task, comm::port<task_notification>);
fn spawn_joinable(-f: sendfn()) -> joinable_task { fn spawn_joinable(+f: sendfn()) -> joinable_task {
let notify_port = comm::port(); let notify_port = comm::port();
let notify_chan = comm::chan(notify_port); let notify_chan = comm::chan(notify_port);
let task = spawn_inner(f, some(notify_chan)); let task = spawn_inner(f, some(notify_chan));
...@@ -189,6 +189,29 @@ fn spawn_joinable(-f: sendfn()) -> joinable_task { ...@@ -189,6 +189,29 @@ fn spawn_joinable(-f: sendfn()) -> joinable_task {
exit(task, task_result); exit(task, task_result);
} }
/*
type connected_fn<ToCh, FrCh> = sendfn(comm::chan<FrCh>, comm::port<ToCh>);
type connected_task<ToCh, FrCh> = {
port: comm::port<FrCh>,
chan: comm::chan<ToCh>,
task: task
};
fn spawn_connected<ToCh:send, FrCh:send>(f: connected_fn<ToCh, FrCh>)
-> connected_fn {
let from_child_port = comm::port<FrCh>();
let from_child_chan = comm::chan(from_child_port);
let get_to_child_port = comm::port<comm::chan<ToCh>>();
let get_to_child_chan = comm::chan(to_child_port);
let child_task = spawn(sendfn[move f]() {
let to_child_port = comm::port<ToCh>();
comm::send(get_to_child_chan, to_child_port);
f(from_child_chan, to_child_port);
});
let to_child_chan = comm::recv(get_out);
ret {port: from_child_port, chan: to_child_chan, task: child_task};
}
*/
/* Section: Operations */ /* Section: Operations */
/* /*
......
// error-pattern:Ensure that the child task runs by failing
fn main() {
// the purpose of this test is to make sure that task::spawn()
// works when provided with a bare function:
task::spawn(startfn);
}
fn startfn() {
assert str::is_empty("Ensure that the child task runs by failing");
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册