提交 bd81adab 编写于 作者: B Brian Anderson

Add task::send and task::recv

上级 73fed011
......@@ -52,6 +52,14 @@ fn clone_chan[T](chan[T] c) -> chan[T] {
ret unsafe::reinterpret_cast(cloned);
}
fn send[T](chan[T] c, &T v) {
c <| v;
}
fn recv[T](port[T] p) -> T {
auto v; p |> v; v
}
// Spawn a task and immediately return a channel for communicating to it
fn worker[T](fn(port[T]) f) -> rec(task task, chan[T] chan) {
// FIXME: This is frighteningly unsafe and only works for
......
......@@ -33,6 +33,14 @@ fn failer() {
assert task::join(failtask) == task::tr_failure;
}
#[test]
fn test_send_recv() {
auto p = port[int]();
auto c = chan(p);
task::send(c, 10);
assert task::recv(p) == 10;
}
#[test]
fn test_worker() {
task::worker(fn(port[int] p) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册