Merge pull request #4167 from catamorphism/issue-3637

Reverse the order of the results of pipes::stream
This commit is contained in:
Tim Chevalier 2012-12-12 12:06:30 -08:00
commit 4ec658eb69
27 changed files with 81 additions and 81 deletions

View File

@ -978,10 +978,10 @@ pub enum Port<T:Send> {
These allow sending or receiving an unlimited number of messages. These allow sending or receiving an unlimited number of messages.
*/ */
pub fn stream<T:Send>() -> (Chan<T>, Port<T>) { pub fn stream<T:Send>() -> (Port<T>, Chan<T>) {
let (c, s) = streamp::init(); let (c, s) = streamp::init();
(Chan_({ mut endp: Some(move c) }), Port_({ mut endp: Some(move s) })) (Port_({ mut endp: Some(move s) }), Chan_({ mut endp: Some(move c) }))
} }
impl<T: Send> Chan<T>: GenericChan<T> { impl<T: Send> Chan<T>: GenericChan<T> {
@ -1070,7 +1070,7 @@ impl<T: Send> PortSet<T> {
} }
fn chan() -> Chan<T> { fn chan() -> Chan<T> {
let (ch, po) = stream(); let (po, ch) = stream();
self.add(move po); self.add(move po);
move ch move ch
} }
@ -1240,8 +1240,8 @@ pub mod rt {
pub mod test { pub mod test {
#[test] #[test]
pub fn test_select2() { pub fn test_select2() {
let (c1, p1) = pipes::stream(); let (p1, c1) = pipes::stream();
let (c2, p2) = pipes::stream(); let (p2, c2) = pipes::stream();
c1.send(~"abc"); c1.send(~"abc");
@ -1264,7 +1264,7 @@ pub mod test {
#[test] #[test]
fn test_peek_terminated() { fn test_peek_terminated() {
let (chan, port): (Chan<int>, Port<int>) = stream(); let (port, chan): (Port<int>, Chan<int>) = stream();
{ {
// Destroy the channel // Destroy the channel

View File

@ -576,7 +576,7 @@ pub mod tests {
for uint::range(0, num_tasks) |_i| { for uint::range(0, num_tasks) |_i| {
let total = total.clone(); let total = total.clone();
let (chan, port) = pipes::stream(); let (port, chan) = pipes::stream();
futures.push(move port); futures.push(move port);
do task::spawn |move total, move chan| { do task::spawn |move total, move chan| {

View File

@ -340,7 +340,7 @@ impl TaskBuilder {
} }
// Construct the future and give it to the caller. // Construct the future and give it to the caller.
let (notify_pipe_ch, notify_pipe_po) = stream::<TaskResult>(); let (notify_pipe_po, notify_pipe_ch) = stream::<TaskResult>();
blk(move notify_pipe_po); blk(move notify_pipe_po);
@ -1211,7 +1211,7 @@ fn test_unkillable() {
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
#[should_fail] #[should_fail]
fn test_unkillable_nested() { fn test_unkillable_nested() {
let (ch, po) = pipes::stream(); let (po, ch) = pipes::stream();
// We want to do this after failing // We want to do this after failing
do spawn_unlinked |move ch| { do spawn_unlinked |move ch| {
@ -1277,7 +1277,7 @@ fn test_child_doesnt_ref_parent() {
#[test] #[test]
fn test_sched_thread_per_core() { fn test_sched_thread_per_core() {
let (chan, port) = pipes::stream(); let (port, chan) = pipes::stream();
do spawn_sched(ThreadPerCore) |move chan| { do spawn_sched(ThreadPerCore) |move chan| {
let cores = rt::rust_num_threads(); let cores = rt::rust_num_threads();
@ -1291,7 +1291,7 @@ fn test_sched_thread_per_core() {
#[test] #[test]
fn test_spawn_thread_on_demand() { fn test_spawn_thread_on_demand() {
let (chan, port) = pipes::stream(); let (port, chan) = pipes::stream();
do spawn_sched(ManualThreads(2)) |move chan| { do spawn_sched(ManualThreads(2)) |move chan| {
let max_threads = rt::rust_sched_threads(); let max_threads = rt::rust_sched_threads();
@ -1299,7 +1299,7 @@ fn test_spawn_thread_on_demand() {
let running_threads = rt::rust_sched_current_nonlazy_threads(); let running_threads = rt::rust_sched_current_nonlazy_threads();
assert(running_threads as int == 1); assert(running_threads as int == 1);
let (chan2, port2) = pipes::stream(); let (port2, chan2) = pipes::stream();
do spawn() |move chan2| { do spawn() |move chan2| {
chan2.send(()); chan2.send(());

View File

@ -670,7 +670,7 @@ fn test_spawn_raw_unsupervise() {
#[test] #[test]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_spawn_raw_notify_success() { fn test_spawn_raw_notify_success() {
let (notify_ch, notify_po) = pipes::stream(); let (notify_po, notify_ch) = pipes::stream();
let opts = { let opts = {
notify_chan: Some(move notify_ch), notify_chan: Some(move notify_ch),
@ -685,7 +685,7 @@ fn test_spawn_raw_notify_success() {
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
fn test_spawn_raw_notify_failure() { fn test_spawn_raw_notify_failure() {
// New bindings for these // New bindings for these
let (notify_ch, notify_po) = pipes::stream(); let (notify_po, notify_ch) = pipes::stream();
let opts = { let opts = {
linked: false, linked: false,

View File

@ -111,12 +111,12 @@ fn pandoc_writer(
os::close(pipe_err.out); os::close(pipe_err.out);
os::close(pipe_in.out); os::close(pipe_in.out);
let (stdout_ch, stdout_po) = pipes::stream(); let (stdout_po, stdout_ch) = pipes::stream();
do task::spawn_sched(task::SingleThreaded) |move stdout_ch| { do task::spawn_sched(task::SingleThreaded) |move stdout_ch| {
stdout_ch.send(readclose(pipe_out.in)); stdout_ch.send(readclose(pipe_out.in));
} }
let (stderr_ch, stderr_po) = pipes::stream(); let (stderr_po, stderr_ch) = pipes::stream();
do task::spawn_sched(task::SingleThreaded) |move stderr_ch| { do task::spawn_sched(task::SingleThreaded) |move stderr_ch| {
stderr_ch.send(readclose(pipe_err.in)); stderr_ch.send(readclose(pipe_err.in));
} }
@ -149,7 +149,7 @@ fn readclose(fd: libc::c_int) -> ~str {
} }
fn generic_writer(+process: fn~(+markdown: ~str)) -> Writer { fn generic_writer(+process: fn~(+markdown: ~str)) -> Writer {
let (setup_ch, setup_po) = pipes::stream(); let (setup_po, setup_ch) = pipes::stream();
do task::spawn |move process, move setup_ch| { do task::spawn |move process, move setup_ch| {
let po: comm::Port<WriteInstr> = comm::Port(); let po: comm::Port<WriteInstr> = comm::Port();
let ch = comm::Chan(&po); let ch = comm::Chan(&po);
@ -279,7 +279,7 @@ pub fn future_writer_factory(
let markdown_po = comm::Port(); let markdown_po = comm::Port();
let markdown_ch = comm::Chan(&markdown_po); let markdown_ch = comm::Chan(&markdown_po);
let writer_factory = fn~(+page: doc::Page) -> Writer { let writer_factory = fn~(+page: doc::Page) -> Writer {
let (writer_ch, writer_po) = pipes::stream(); let (writer_po, writer_ch) = pipes::stream();
do task::spawn |move writer_ch| { do task::spawn |move writer_ch| {
let (writer, future) = future_writer(); let (writer, future) = future_writer();
writer_ch.send(move writer); writer_ch.send(move writer);
@ -293,7 +293,7 @@ pub fn future_writer_factory(
} }
fn future_writer() -> (Writer, future::Future<~str>) { fn future_writer() -> (Writer, future::Future<~str>) {
let (chan, port) = pipes::stream(); let (port, chan) = pipes::stream();
let writer = fn~(move chan, +instr: WriteInstr) { let writer = fn~(move chan, +instr: WriteInstr) {
chan.send(copy instr); chan.send(copy instr);
}; };

View File

@ -471,7 +471,7 @@ mod tests {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::ARC(v); let arc_v = arc::ARC(v);
let (c, p) = pipes::stream(); let (p, c) = pipes::stream();
do task::spawn() |move c| { do task::spawn() |move c| {
let p = pipes::PortSet(); let p = pipes::PortSet();
@ -517,7 +517,7 @@ mod tests {
fn test_arc_condvar_poison() { fn test_arc_condvar_poison() {
let arc = ~MutexARC(1); let arc = ~MutexARC(1);
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
let (c,p) = pipes::stream(); let (p, c) = pipes::stream();
do task::spawn_unlinked |move arc2, move p| { do task::spawn_unlinked |move arc2, move p| {
let _ = p.recv(); let _ = p.recv();
@ -551,7 +551,7 @@ mod tests {
fn test_mutex_arc_unwrap_poison() { fn test_mutex_arc_unwrap_poison() {
let arc = MutexARC(1); let arc = MutexARC(1);
let arc2 = ~(&arc).clone(); let arc2 = ~(&arc).clone();
let (c,p) = pipes::stream(); let (p, c) = pipes::stream();
do task::spawn |move c, move arc2| { do task::spawn |move c, move arc2| {
do arc2.access |one| { do arc2.access |one| {
c.send(()); c.send(());
@ -649,7 +649,7 @@ mod tests {
fn test_rw_arc() { fn test_rw_arc() {
let arc = ~RWARC(0); let arc = ~RWARC(0);
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
do task::spawn |move arc2, move c| { do task::spawn |move arc2, move c| {
do arc2.write |num| { do arc2.write |num| {
@ -695,7 +695,7 @@ mod tests {
// Reader tasks // Reader tasks
let mut reader_convos = ~[]; let mut reader_convos = ~[];
for 10.times { for 10.times {
let ((rc1,rp1),(rc2,rp2)) = (pipes::stream(),pipes::stream()); let ((rp1,rc1),(rp2,rc2)) = (pipes::stream(),pipes::stream());
reader_convos.push((move rc1, move rp2)); reader_convos.push((move rc1, move rp2));
let arcn = ~arc.clone(); let arcn = ~arc.clone();
do task::spawn |move rp1, move rc2, move arcn| { do task::spawn |move rp1, move rc2, move arcn| {
@ -709,7 +709,7 @@ mod tests {
// Writer task // Writer task
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
let ((wc1,wp1),(wc2,wp2)) = (pipes::stream(),pipes::stream()); let ((wp1,wc1),(wp2,wc2)) = (pipes::stream(),pipes::stream());
do task::spawn |move arc2, move wc2, move wp1| { do task::spawn |move arc2, move wc2, move wp1| {
wp1.recv(); wp1.recv();
do arc2.write_cond |state, cond| { do arc2.write_cond |state, cond| {

View File

@ -64,8 +64,8 @@ impl<T: Send, U: Send> DuplexStream<T, U> : Selectable {
pub fn DuplexStream<T: Send, U: Send>() pub fn DuplexStream<T: Send, U: Send>()
-> (DuplexStream<T, U>, DuplexStream<U, T>) -> (DuplexStream<T, U>, DuplexStream<U, T>)
{ {
let (c2, p1) = pipes::stream(); let (p1, c2) = pipes::stream();
let (c1, p2) = pipes::stream(); let (p2, c1) = pipes::stream();
(DuplexStream { (DuplexStream {
chan: move c1, chan: move c1,
port: move p1 port: move p1

View File

@ -34,7 +34,7 @@ struct Waitqueue { head: pipes::Port<SignalEnd>,
tail: pipes::Chan<SignalEnd> } tail: pipes::Chan<SignalEnd> }
fn new_waitqueue() -> Waitqueue { fn new_waitqueue() -> Waitqueue {
let (block_tail, block_head) = pipes::stream(); let (block_head, block_tail) = pipes::stream();
Waitqueue { head: move block_head, tail: move block_tail } Waitqueue { head: move block_head, tail: move block_tail }
} }
@ -733,7 +733,7 @@ mod tests {
#[test] #[test]
fn test_sem_as_cvar() { fn test_sem_as_cvar() {
/* Child waits and parent signals */ /* Child waits and parent signals */
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
let s = ~semaphore(0); let s = ~semaphore(0);
let s2 = ~s.clone(); let s2 = ~s.clone();
do task::spawn |move s2, move c| { do task::spawn |move s2, move c| {
@ -745,7 +745,7 @@ mod tests {
let _ = p.recv(); let _ = p.recv();
/* Parent waits and child signals */ /* Parent waits and child signals */
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
let s = ~semaphore(0); let s = ~semaphore(0);
let s2 = ~s.clone(); let s2 = ~s.clone();
do task::spawn |move s2, move p| { do task::spawn |move s2, move p| {
@ -762,8 +762,8 @@ mod tests {
// time, and shake hands. // time, and shake hands.
let s = ~semaphore(2); let s = ~semaphore(2);
let s2 = ~s.clone(); let s2 = ~s.clone();
let (c1,p1) = pipes::stream(); let (p1,c1) = pipes::stream();
let (c2,p2) = pipes::stream(); let (p2,c2) = pipes::stream();
do task::spawn |move s2, move c1, move p2| { do task::spawn |move s2, move c1, move p2| {
do s2.access { do s2.access {
let _ = p2.recv(); let _ = p2.recv();
@ -782,7 +782,7 @@ mod tests {
do task::spawn_sched(task::ManualThreads(1)) { do task::spawn_sched(task::ManualThreads(1)) {
let s = ~semaphore(1); let s = ~semaphore(1);
let s2 = ~s.clone(); let s2 = ~s.clone();
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
let child_data = ~mut Some((move s2, move c)); let child_data = ~mut Some((move s2, move c));
do s.access { do s.access {
let (s2,c) = option::swap_unwrap(child_data); let (s2,c) = option::swap_unwrap(child_data);
@ -804,7 +804,7 @@ mod tests {
fn test_mutex_lock() { fn test_mutex_lock() {
// Unsafely achieve shared state, and do the textbook // Unsafely achieve shared state, and do the textbook
// "load tmp = move ptr; inc tmp; store ptr <- tmp" dance. // "load tmp = move ptr; inc tmp; store ptr <- tmp" dance.
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
let m = ~Mutex(); let m = ~Mutex();
let m2 = ~m.clone(); let m2 = ~m.clone();
let mut sharedstate = ~0; let mut sharedstate = ~0;
@ -847,7 +847,7 @@ mod tests {
cond.wait(); cond.wait();
} }
// Parent wakes up child // Parent wakes up child
let (chan,port) = pipes::stream(); let (port,chan) = pipes::stream();
let m3 = ~m.clone(); let m3 = ~m.clone();
do task::spawn |move chan, move m3| { do task::spawn |move chan, move m3| {
do m3.lock_cond |cond| { do m3.lock_cond |cond| {
@ -870,7 +870,7 @@ mod tests {
for num_waiters.times { for num_waiters.times {
let mi = ~m.clone(); let mi = ~m.clone();
let (chan, port) = pipes::stream(); let (port, chan) = pipes::stream();
ports.push(move port); ports.push(move port);
do task::spawn |move chan, move mi| { do task::spawn |move chan, move mi| {
do mi.lock_cond |cond| { do mi.lock_cond |cond| {
@ -932,7 +932,7 @@ mod tests {
let m2 = ~m.clone(); let m2 = ~m.clone();
let result: result::Result<(),()> = do task::try |move m2| { let result: result::Result<(),()> = do task::try |move m2| {
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
do task::spawn |move p| { // linked do task::spawn |move p| { // linked
let _ = p.recv(); // wait for sibling to get in the mutex let _ = p.recv(); // wait for sibling to get in the mutex
task::yield(); task::yield();
@ -954,12 +954,12 @@ mod tests {
fn test_mutex_killed_broadcast() { fn test_mutex_killed_broadcast() {
let m = ~Mutex(); let m = ~Mutex();
let m2 = ~m.clone(); let m2 = ~m.clone();
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
let result: result::Result<(),()> = do task::try |move c, move m2| { let result: result::Result<(),()> = do task::try |move c, move m2| {
let mut sibling_convos = ~[]; let mut sibling_convos = ~[];
for 2.times { for 2.times {
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
let c = ~mut Some(move c); let c = ~mut Some(move c);
sibling_convos.push(move p); sibling_convos.push(move p);
let mi = ~m2.clone(); let mi = ~m2.clone();
@ -1022,7 +1022,7 @@ mod tests {
let result = do task::try { let result = do task::try {
let m = ~mutex_with_condvars(2); let m = ~mutex_with_condvars(2);
let m2 = ~m.clone(); let m2 = ~m.clone();
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
do task::spawn |move m2, move c| { do task::spawn |move m2, move c| {
do m2.lock_cond |cond| { do m2.lock_cond |cond| {
c.send(()); c.send(());
@ -1082,7 +1082,7 @@ mod tests {
mode2: RWlockMode) { mode2: RWlockMode) {
// Test mutual exclusion between readers and writers. Just like the // Test mutual exclusion between readers and writers. Just like the
// mutex mutual exclusion test, a ways above. // mutex mutual exclusion test, a ways above.
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
let x2 = ~x.clone(); let x2 = ~x.clone();
let mut sharedstate = ~0; let mut sharedstate = ~0;
let ptr = ptr::addr_of(&(*sharedstate)); let ptr = ptr::addr_of(&(*sharedstate));
@ -1127,8 +1127,8 @@ mod tests {
mode2: RWlockMode, make_mode2_go_first: bool) { mode2: RWlockMode, make_mode2_go_first: bool) {
// Much like sem_multi_resource. // Much like sem_multi_resource.
let x2 = ~x.clone(); let x2 = ~x.clone();
let (c1,p1) = pipes::stream(); let (p1,c1) = pipes::stream();
let (c2,p2) = pipes::stream(); let (p2,c2) = pipes::stream();
do task::spawn |move c1, move x2, move p2| { do task::spawn |move c1, move x2, move p2| {
if !make_mode2_go_first { if !make_mode2_go_first {
let _ = p2.recv(); // parent sends to us once it locks, or ... let _ = p2.recv(); // parent sends to us once it locks, or ...
@ -1193,7 +1193,7 @@ mod tests {
cond.wait(); cond.wait();
} }
// Parent wakes up child // Parent wakes up child
let (chan,port) = pipes::stream(); let (port,chan) = pipes::stream();
let x3 = ~x.clone(); let x3 = ~x.clone();
do task::spawn |move x3, move chan| { do task::spawn |move x3, move chan| {
do x3.write_cond |cond| { do x3.write_cond |cond| {
@ -1229,7 +1229,7 @@ mod tests {
for num_waiters.times { for num_waiters.times {
let xi = ~x.clone(); let xi = ~x.clone();
let (chan, port) = pipes::stream(); let (port, chan) = pipes::stream();
ports.push(move port); ports.push(move port);
do task::spawn |move chan, move xi| { do task::spawn |move chan, move xi| {
do lock_cond(xi, dg1) |cond| { do lock_cond(xi, dg1) |cond| {

View File

@ -42,7 +42,7 @@ pub impl<T> TaskPool<T> {
assert n_tasks >= 1; assert n_tasks >= 1;
let channels = do vec::from_fn(n_tasks) |i| { let channels = do vec::from_fn(n_tasks) |i| {
let (chan, port) = pipes::stream::<Msg<T>>(); let (port, chan) = pipes::stream::<Msg<T>>();
let init_fn = init_fn_factory(); let init_fn = init_fn_factory();
let task_body: ~fn() = |move port, move init_fn| { let task_body: ~fn() = |move port, move init_fn| {

View File

@ -55,8 +55,8 @@ fn server(requests: Port<request>, responses: pipes::Chan<uint>) {
} }
fn run(args: &[~str]) { fn run(args: &[~str]) {
let (to_parent, from_child) = pipes::stream(); let (from_child, to_parent) = pipes::stream();
let (to_child, from_parent) = pipes::stream(); let (from_parent, to_child) = pipes::stream();
let to_child = SharedChan(move to_child); let to_child = SharedChan(move to_child);

View File

@ -33,7 +33,7 @@ enum request {
} }
fn server(requests: PortSet<request>, responses: pipes::Chan<uint>) { fn server(requests: PortSet<request>, responses: pipes::Chan<uint>) {
let mut count = 0u; let mut count = 0;
let mut done = false; let mut done = false;
while !done { while !done {
match requests.try_recv() { match requests.try_recv() {
@ -51,8 +51,8 @@ fn server(requests: PortSet<request>, responses: pipes::Chan<uint>) {
} }
fn run(args: &[~str]) { fn run(args: &[~str]) {
let (to_parent, from_child) = pipes::stream(); let (from_child, to_parent) = pipes::stream();
let (to_child, from_parent_) = pipes::stream(); let (from_parent_, to_child) = pipes::stream();
let from_parent = PortSet(); let from_parent = PortSet();
from_parent.add(move from_parent_); from_parent.add(move from_parent_);
@ -62,7 +62,7 @@ fn run(args: &[~str]) {
let start = std::time::precise_time_s(); let start = std::time::precise_time_s();
let mut worker_results = ~[]; let mut worker_results = ~[];
for uint::range(0, workers) |_i| { for uint::range(0, workers) |_i| {
let (to_child, from_parent_) = pipes::stream(); let (from_parent_, to_child) = pipes::stream();
from_parent.add(move from_parent_); from_parent.add(move from_parent_);
do task::task().future_result(|+r| { do task::task().future_result(|+r| {
worker_results.push(move r); worker_results.push(move r);

View File

@ -157,11 +157,11 @@ fn main() {
let sz = *sz; let sz = *sz;
let mut stream = None; let mut stream = None;
stream <-> streams[ii]; stream <-> streams[ii];
let (to_parent_, from_child_) = option::unwrap(move stream); let (from_child_, to_parent_) = option::unwrap(move stream);
from_child.push(move from_child_); from_child.push(move from_child_);
let (to_child, from_parent) = pipes::stream(); let (from_parent, to_child) = pipes::stream();
do task::spawn_with(move from_parent) |move to_parent_, from_parent| { do task::spawn_with(move from_parent) |move to_parent_, from_parent| {
make_sequence_processor(sz, from_parent, to_parent_); make_sequence_processor(sz, from_parent, to_parent_);

View File

@ -50,7 +50,7 @@ fn fib(n: int) -> int {
} }
} }
let (ch, p) = pipes::stream(); let (p, ch) = pipes::stream();
let _t = task::spawn(|move ch| pfib(ch, n) ); let _t = task::spawn(|move ch| pfib(ch, n) );
p.recv() p.recv()
} }

View File

@ -43,7 +43,7 @@ fn main() {
copy args copy args
}; };
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
child_generation(uint::from_str(args[1]).get(), move c); child_generation(uint::from_str(args[1]).get(), move c);
if p.try_recv().is_none() { if p.try_recv().is_none() {
fail ~"it happened when we slumbered"; fail ~"it happened when we slumbered";

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
fn main() { fn main() {
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
let x = Some(p); let x = Some(p);
c.send(false); c.send(false);
match move x { match move x {

View File

@ -11,15 +11,15 @@
// xfail-fast // xfail-fast
fn main() { fn main() {
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
do task::try |move c| { do task::try |move c| {
let (c2,p2) = pipes::stream(); let (p2,c2) = pipes::stream();
do task::spawn |move p2| { do task::spawn |move p2| {
p2.recv(); p2.recv();
error!("sibling fails"); error!("sibling fails");
fail; fail;
} }
let (c3,p3) = pipes::stream(); let (p3,c3) = pipes::stream();
c.send(move c3); c.send(move c3);
c2.send(()); c2.send(());
error!("child blocks"); error!("child blocks");

View File

@ -13,19 +13,19 @@
use pipes::{Select2, Selectable}; use pipes::{Select2, Selectable};
fn main() { fn main() {
let (c,p) = pipes::stream(); let (p,c) = pipes::stream();
do task::try |move c| { do task::try |move c| {
let (c2,p2) = pipes::stream(); let (p2,c2) = pipes::stream();
do task::spawn |move p2| { do task::spawn |move p2| {
p2.recv(); p2.recv();
error!("sibling fails"); error!("sibling fails");
fail; fail;
} }
let (c3,p3) = pipes::stream(); let (p3,c3) = pipes::stream();
c.send(move c3); c.send(move c3);
c2.send(()); c2.send(());
error!("child blocks"); error!("child blocks");
let (c, p) = pipes::stream(); let (p, c) = pipes::stream();
(move p, move p3).select(); (move p, move p3).select();
c.send(()); c.send(());
}; };

View File

@ -28,7 +28,7 @@ fn test05_start(ch : Chan<int>) {
} }
fn test05() { fn test05() {
let (ch, po) = pipes::stream(); let (po, ch) = pipes::stream();
task::spawn(|move ch| test05_start(ch) ); task::spawn(|move ch| test05_start(ch) );
let mut value = po.recv(); let mut value = po.recv();
log(error, value); log(error, value);

View File

@ -14,7 +14,7 @@
extern mod std; extern mod std;
fn start(c: pipes::Chan<pipes::Chan<~str>>) { fn start(c: pipes::Chan<pipes::Chan<~str>>) {
let (ch, p) = pipes::stream(); let (p, ch) = pipes::stream();
c.send(move ch); c.send(move ch);
let mut a; let mut a;
@ -28,7 +28,7 @@ fn start(c: pipes::Chan<pipes::Chan<~str>>) {
} }
fn main() { fn main() {
let (ch, p) = pipes::stream(); let (p, ch) = pipes::stream();
let child = task::spawn(|move ch| start(ch) ); let child = task::spawn(|move ch| start(ch) );
let c = p.recv(); let c = p.recv();

View File

@ -14,12 +14,12 @@
extern mod std; extern mod std;
fn start(c: pipes::Chan<pipes::Chan<int>>) { fn start(c: pipes::Chan<pipes::Chan<int>>) {
let (ch, p) = pipes::stream(); let (p, ch) = pipes::stream();
c.send(move ch); c.send(move ch);
} }
fn main() { fn main() {
let (ch, p) = pipes::stream(); let (p, ch) = pipes::stream();
let child = task::spawn(|move ch| start(ch) ); let child = task::spawn(|move ch| start(ch) );
let c = p.recv(); let c = p.recv();
} }

View File

@ -21,7 +21,7 @@ fn start(c: pipes::Chan<int>, start: int, number_of_messages: int) {
fn main() { fn main() {
debug!("Check that we don't deadlock."); debug!("Check that we don't deadlock.");
let (ch, p) = pipes::stream(); let (p, ch) = pipes::stream();
task::try(|move ch| start(ch, 0, 10) ); task::try(|move ch| start(ch, 0, 10) );
debug!("Joined task"); debug!("Joined task");
} }

View File

@ -18,7 +18,7 @@ fn main() {
let mut i = 10; let mut i = 10;
while (i > 0) { while (i > 0) {
log(debug, i); log(debug, i);
let (ch, p) = pipes::stream(); let (p, ch) = pipes::stream();
po.add(move p); po.add(move p);
task::spawn(|move ch, copy i| child(i, ch) ); task::spawn(|move ch, copy i| child(i, ch) );
i = i - 1; i = i - 1;

View File

@ -27,7 +27,7 @@ fn main() {
// is likely to terminate before the child completes, so from // is likely to terminate before the child completes, so from
// the child's point of view the receiver may die. We should // the child's point of view the receiver may die. We should
// drop messages on the floor in this case, and not crash! // drop messages on the floor in this case, and not crash!
let (ch, p) = pipes::stream(); let (p, ch) = pipes::stream();
task::spawn(|move ch| start(ch, 10)); task::spawn(|move ch| start(ch, 10));
p.recv(); p.recv();
} }

View File

@ -20,7 +20,7 @@ use pipes::Chan;
fn test_rec() { fn test_rec() {
type r = {val0: int, val1: u8, val2: char}; type r = {val0: int, val1: u8, val2: char};
let (ch, po) = pipes::stream(); let (po, ch) = pipes::stream();
let r0: r = {val0: 0, val1: 1u8, val2: '2'}; let r0: r = {val0: 0, val1: 1u8, val2: '2'};
ch.send(r0); ch.send(r0);
let mut r1: r; let mut r1: r;
@ -31,7 +31,7 @@ fn test_rec() {
} }
fn test_vec() { fn test_vec() {
let (ch, po) = pipes::stream(); let (po, ch) = pipes::stream();
let v0: ~[int] = ~[0, 1, 2]; let v0: ~[int] = ~[0, 1, 2];
ch.send(v0); ch.send(v0);
let v1 = po.recv(); let v1 = po.recv();
@ -41,7 +41,7 @@ fn test_vec() {
} }
fn test_str() { fn test_str() {
let (ch, po) = pipes::stream(); let (po, ch) = pipes::stream();
let s0 = ~"test"; let s0 = ~"test";
ch.send(s0); ch.send(s0);
let s1 = po.recv(); let s1 = po.recv();
@ -85,7 +85,7 @@ impl t : cmp::Eq {
} }
fn test_tag() { fn test_tag() {
let (ch, po) = pipes::stream(); let (po, ch) = pipes::stream();
ch.send(tag1); ch.send(tag1);
ch.send(tag2(10)); ch.send(tag2(10));
ch.send(tag3(10, 11u8, 'A')); ch.send(tag3(10, 11u8, 'A'));
@ -99,8 +99,8 @@ fn test_tag() {
} }
fn test_chan() { fn test_chan() {
let (ch, po) = pipes::stream(); let (po, ch) = pipes::stream();
let (ch0, po0) = pipes::stream(); let (po0, ch0) = pipes::stream();
ch.send(move ch0); ch.send(move ch0);
let ch1 = po.recv(); let ch1 = po.recv();
// Does the transmitted channel still work? // Does the transmitted channel still work?

View File

@ -16,7 +16,7 @@ fn main() { test00(); }
fn test00() { fn test00() {
let mut r: int = 0; let mut r: int = 0;
let mut sum: int = 0; let mut sum: int = 0;
let (c, p) = pipes::stream(); let (p, c) = pipes::stream();
c.send(1); c.send(1);
c.send(2); c.send(2);
c.send(3); c.send(3);

View File

@ -15,7 +15,7 @@ fn main() { test00(); }
fn test00() { fn test00() {
let r: int = 0; let r: int = 0;
let mut sum: int = 0; let mut sum: int = 0;
let (c, p) = pipes::stream(); let (p, c) = pipes::stream();
let number_of_messages: int = 1000; let number_of_messages: int = 1000;
let mut i: int = 0; let mut i: int = 0;
while i < number_of_messages { c.send(i + 0); i += 1; } while i < number_of_messages { c.send(i + 0); i += 1; }

View File

@ -15,7 +15,7 @@ use pipes::{Port, Chan};
message. message.
*/ */
fn main() { fn main() {
let (ch, po) = pipes::stream(); let (po, ch) = pipes::stream();
ch.send(42); ch.send(42);
let r = po.recv(); let r = po.recv();
log(error, r); log(error, r);