Skip to content

Commit

Permalink
Removing do keyword from libextra
Browse files Browse the repository at this point in the history
  • Loading branch information
bytbox committed Jan 29, 2014
1 parent d904179 commit badc580
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 123 deletions.
72 changes: 36 additions & 36 deletions src/libextra/arc.rs
Expand Up @@ -28,12 +28,12 @@
* let (port, chan) = Chan::new();
* chan.send(shared_numbers.clone());
*
* do spawn {
* spawn(proc() {
* let shared_numbers = port.recv();
* let local_numbers = shared_numbers.get();
*
* // Work with the local numbers
* }
* });
* }
* ```
*/
Expand Down Expand Up @@ -567,12 +567,12 @@ mod tests {

let (p, c) = Chan::new();

do task::spawn {
task::spawn(proc() {
let arc_v: Arc<~[int]> = p.recv();

let v = arc_v.get().clone();
assert_eq!(v[3], 4);
};
});

c.send(arc_v.clone());

Expand All @@ -587,14 +587,14 @@ mod tests {
let arc = ~MutexArc::new(false);
let arc2 = ~arc.clone();
let (p,c) = Chan::new();
do task::spawn {
task::spawn(proc() {
// wait until parent gets in
p.recv();
arc2.access_cond(|state, cond| {
*state = true;
cond.signal();
})
}
});

arc.access_cond(|state, cond| {
c.send(());
Expand All @@ -611,14 +611,14 @@ mod tests {
let arc2 = ~arc.clone();
let (p, c) = Chan::new();

do spawn {
spawn(proc() {
let _ = p.recv();
arc2.access_cond(|one, cond| {
cond.signal();
// Parent should fail when it wakes up.
assert_eq!(*one, 0);
})
}
});

arc.access_cond(|one, cond| {
c.send(());
Expand All @@ -632,11 +632,11 @@ mod tests {
fn test_mutex_arc_poison() {
let arc = ~MutexArc::new(1);
let arc2 = ~arc.clone();
do task::try || {
task::try(proc() {
arc2.access(|one| {
assert_eq!(*one, 2);
})
};
});
arc.access(|one| {
assert_eq!(*one, 1);
})
Expand All @@ -649,13 +649,13 @@ mod tests {
// to underlaying data.
let arc = ~MutexArc::new(1);
let arc2 = ~MutexArc::new(*arc);
do task::spawn || {
task::spawn(proc() {
(*arc2).unsafe_access(|mutex| {
(*mutex).access(|one| {
assert!(*one == 1);
})
})
};
});
}
}

Expand All @@ -682,11 +682,11 @@ mod tests {
fn test_rw_arc_poison_wr() {
let arc = RWArc::new(1);
let arc2 = arc.clone();
do task::try {
task::try(proc() {
arc2.write(|one| {
assert_eq!(*one, 2);
})
};
});
arc.read(|one| {
assert_eq!(*one, 1);
})
Expand All @@ -696,11 +696,11 @@ mod tests {
fn test_rw_arc_poison_ww() {
let arc = RWArc::new(1);
let arc2 = arc.clone();
do task::try {
task::try(proc() {
arc2.write(|one| {
assert_eq!(*one, 2);
})
};
});
arc.write(|one| {
assert_eq!(*one, 1);
})
Expand All @@ -709,13 +709,13 @@ mod tests {
fn test_rw_arc_poison_dw() {
let arc = RWArc::new(1);
let arc2 = arc.clone();
do task::try {
task::try(proc() {
arc2.write_downgrade(|mut write_mode| {
write_mode.write(|one| {
assert_eq!(*one, 2);
})
})
};
});
arc.write(|one| {
assert_eq!(*one, 1);
})
Expand All @@ -724,11 +724,11 @@ mod tests {
fn test_rw_arc_no_poison_rr() {
let arc = RWArc::new(1);
let arc2 = arc.clone();
do task::try {
task::try(proc() {
arc2.read(|one| {
assert_eq!(*one, 2);
})
};
});
arc.read(|one| {
assert_eq!(*one, 1);
})
Expand All @@ -737,11 +737,11 @@ mod tests {
fn test_rw_arc_no_poison_rw() {
let arc = RWArc::new(1);
let arc2 = arc.clone();
do task::try {
task::try(proc() {
arc2.read(|one| {
assert_eq!(*one, 2);
})
};
});
arc.write(|one| {
assert_eq!(*one, 1);
})
Expand All @@ -750,14 +750,14 @@ mod tests {
fn test_rw_arc_no_poison_dr() {
let arc = RWArc::new(1);
let arc2 = arc.clone();
do task::try {
task::try(proc() {
arc2.write_downgrade(|write_mode| {
let read_mode = arc2.downgrade(write_mode);
read_mode.read(|one| {
assert_eq!(*one, 2);
})
})
};
});
arc.write(|one| {
assert_eq!(*one, 1);
})
Expand All @@ -768,7 +768,7 @@ mod tests {
let arc2 = arc.clone();
let (p, c) = Chan::new();

do task::spawn {
task::spawn(proc() {
arc2.write(|num| {
10.times(|| {
let tmp = *num;
Expand All @@ -778,19 +778,19 @@ mod tests {
});
c.send(());
})
}
});

// Readers try to catch the writer in the act
let mut children = ~[];
5.times(|| {
let arc3 = arc.clone();
let mut builder = task::task();
children.push(builder.future_result());
do builder.spawn {
builder.spawn(proc() {
arc3.read(|num| {
assert!(*num >= 0);
})
}
});
});

// Wait for children to pass their asserts
Expand Down Expand Up @@ -840,19 +840,19 @@ mod tests {
let ((rp1, rc1), (rp2, rc2)) = (Chan::new(), Chan::new());
reader_convos.push((rc1, rp2));
let arcn = arc.clone();
do task::spawn {
task::spawn(proc() {
rp1.recv(); // wait for downgrader to give go-ahead
arcn.read(|state| {
assert_eq!(*state, 31337);
rc2.send(());
})
}
});
});

// Writer task
let arc2 = arc.clone();
let ((wp1, wc1), (wp2, wc2)) = (Chan::new(), Chan::new());
do task::spawn || {
task::spawn(proc() {
wp1.recv();
arc2.write_cond(|state, cond| {
assert_eq!(*state, 0);
Expand All @@ -867,7 +867,7 @@ mod tests {
*state = 42;
});
wc2.send(());
}
});

// Downgrader (us)
arc.write_downgrade(|mut write_mode| {
Expand Down Expand Up @@ -912,7 +912,7 @@ mod tests {

// writer task
let xw = x.clone();
do task::spawn {
task::spawn(proc() {
xw.write_cond(|state, c| {
wc.send(()); // tell downgrader it's ok to go
c.wait();
Expand All @@ -921,7 +921,7 @@ mod tests {
// trying to receive the "reader cloud lock hand-off".
*state = false;
})
}
});

wp.recv(); // wait for writer to get in

Expand All @@ -934,10 +934,10 @@ mod tests {
// make a reader task to trigger the "reader cloud lock" handoff
let xr = x.clone();
let (rp, rc) = Chan::new();
do task::spawn {
task::spawn(proc() {
rc.send(());
xr.read(|_state| { })
}
});
rp.recv(); // wait for reader task to exist

let read_mode = x.downgrade(write_mode);
Expand Down
20 changes: 10 additions & 10 deletions src/libextra/comm.rs
Expand Up @@ -115,9 +115,9 @@ mod test {
pub fn basic_rendezvous_test() {
let (port, chan) = rendezvous();

do spawn {
spawn(proc() {
chan.send("abc");
}
});

assert!(port.recv() == "abc");
}
Expand All @@ -126,40 +126,40 @@ mod test {
fn recv_a_lot() {
// Rendezvous streams should be able to handle any number of messages being sent
let (port, chan) = rendezvous();
do spawn {
spawn(proc() {
10000.times(|| { chan.send(()) })
}
});
10000.times(|| { port.recv() })
}

#[test]
fn send_and_fail_and_try_recv() {
let (port, chan) = rendezvous();
do spawn {
spawn(proc() {
chan.duplex_stream.send(()); // Can't access this field outside this module
fail!()
}
});
port.recv()
}

#[test]
fn try_send_and_recv_then_fail_before_ack() {
let (port, chan) = rendezvous();
do spawn {
spawn(proc() {
port.duplex_stream.recv();
fail!()
}
});
chan.try_send(());
}

#[test]
#[should_fail]
fn send_and_recv_then_fail_before_ack() {
let (port, chan) = rendezvous();
do spawn {
spawn(proc() {
port.duplex_stream.recv();
fail!()
}
});
chan.send(());
}
}
4 changes: 2 additions & 2 deletions src/libextra/dlist.rs
Expand Up @@ -971,10 +971,10 @@ mod tests {
#[test]
fn test_send() {
let n = list_from([1,2,3]);
do spawn {
spawn(proc() {
check_links(&n);
assert_eq!(~[&1,&2,&3], n.iter().collect::<~[&int]>());
}
});
}

#[test]
Expand Down
16 changes: 8 additions & 8 deletions src/libextra/future.rs
Expand Up @@ -18,7 +18,7 @@
* use extra::future::Future;
* # fn fib(n: uint) -> uint {42};
* # fn make_a_sandwich() {};
* let mut delayed_fib = do Future::spawn { fib(5000) };
* let mut delayed_fib = Future::spawn(proc() { fib(5000) });
* make_a_sandwich();
* println!("fib(5000) = {}", delayed_fib.get())
* ```
Expand Down Expand Up @@ -112,9 +112,9 @@ impl<A:Send> Future<A> {
* waiting for the result to be received on the port.
*/

do Future::from_fn {
Future::from_fn(proc() {
port.recv()
}
})
}

pub fn spawn(blk: proc() -> A) -> Future<A> {
Expand All @@ -127,9 +127,9 @@ impl<A:Send> Future<A> {

let (port, chan) = Chan::new();

do spawn {
spawn(proc() {
chan.send(blk());
}
});

Future::from_port(port)
}
Expand Down Expand Up @@ -195,11 +195,11 @@ mod test {
#[test]
fn test_sendable_future() {
let expected = "schlorf";
let f = do Future::spawn { expected };
do task::spawn {
let f = Future::spawn(proc() { expected });
task::spawn(proc() {
let mut f = f;
let actual = f.get();
assert_eq!(actual, expected);
}
});
}
}

0 comments on commit badc580

Please sign in to comment.