std: Second pass stabilization for comm
This commit is a second pass stabilization for the `std::comm` module,
performing the following actions:
* The entire `std::comm` module was moved under `std::sync::mpsc`. This movement
reflects that channels are just yet another synchronization primitive, and
they don't necessarily deserve a special place outside of the other
concurrency primitives that the standard library offers.
* The `send` and `recv` methods have all been removed.
* The `send_opt` and `recv_opt` methods have been renamed to `send` and `recv`.
This means that all send/receive operations return a `Result` now indicating
whether the operation was successful or not.
* The error type of `send` is now a `SendError` to implement a custom error
message and allow for `unwrap()`. The error type contains an `into_inner`
method to extract the value.
* The error type of `recv` is now `RecvError` for the same reasons as `send`.
* The `TryRecvError` and `TrySendError` types have had public reexports removed
of their variants and the variant names have been tweaked with enum
namespacing rules.
* The `Messages` iterator is renamed to `Iter`
This functionality is now all `#[stable]`:
* `Sender`
* `SyncSender`
* `Receiver`
* `std::sync::mpsc`
* `channel`
* `sync_channel`
* `Iter`
* `Sender::send`
* `Sender::clone`
* `SyncSender::send`
* `SyncSender::try_send`
* `SyncSender::clone`
* `Receiver::recv`
* `Receiver::try_recv`
* `Receiver::iter`
* `SendError`
* `RecvError`
* `TrySendError::{mod, Full, Disconnected}`
* `TryRecvError::{mod, Empty, Disconnected}`
* `SendError::into_inner`
* `TrySendError::into_inner`
This is a breaking change due to the modification of where this module is
located, as well as the changing of the semantics of `send` and `recv`. Most
programs just need to rename imports of `std::comm` to `std::sync::mpsc` and
add calls to `unwrap` after a send or a receive operation.
[breaking-change]
This commit is contained in:
parent
bb8f4fc3b7
commit
bc83a009f6
109 changed files with 1175 additions and 1206 deletions
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::{Receiver, channel};
|
||||
use std::sync::mpsc::{Receiver, channel};
|
||||
|
||||
pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
|
||||
let (tx, rx) = channel();
|
||||
|
|
|
|||
|
|
@ -8,15 +8,16 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
fn main() {
|
||||
let (tx, rx) = channel();
|
||||
let x = Some(rx);
|
||||
tx.send(false);
|
||||
match x {
|
||||
Some(z) if z.recv() => { panic!() }, //~ ERROR cannot bind by-move into a pattern guard
|
||||
Some(z) => { assert!(!z.recv()); },
|
||||
Some(z) if z.recv().unwrap() => { panic!() },
|
||||
//~^ ERROR cannot bind by-move into a pattern guard
|
||||
Some(z) => { assert!(!z.recv().unwrap()); },
|
||||
None => panic!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// Tests (negatively) the ability for the Self type in default methods
|
||||
// to use capabilities granted by builtin kinds as supertraits.
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
trait Foo : Sync+'static {
|
||||
fn foo(self, mut chan: Sender<Self>) { }
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::Receiver;
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
fn test<T: Sync>() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::Sender;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
fn test<T: Sync>() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread::Thread;
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
// Test that a class with an unsendable field can't be
|
||||
// sent
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// Basic boolean tests
|
||||
|
||||
use std::cmp::{Equal, Greater, Less};
|
||||
use std::cmp::Ordering::{Equal, Greater, Less};
|
||||
use std::ops::{BitAnd, BitOr, BitXor};
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
// a Send. Basically this just makes sure rustc is using
|
||||
// each_bound_trait_and_supertraits in type_contents correctly.
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
trait Bar : Send { }
|
||||
trait Foo : Bar { }
|
||||
|
|
@ -23,11 +23,11 @@ impl <T: Send> Foo for T { }
|
|||
impl <T: Send> Bar for T { }
|
||||
|
||||
fn foo<T: Foo>(val: T, chan: Sender<T>) {
|
||||
chan.send(val);
|
||||
chan.send(val).unwrap();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
foo(31337i, tx);
|
||||
assert!(rx.recv() == 31337i);
|
||||
assert!(rx.recv().unwrap() == 31337i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
extern crate trait_superkinds_in_metadata;
|
||||
|
||||
use std::comm::{channel, Sender, Receiver};
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare};
|
||||
|
||||
#[deriving(PartialEq)]
|
||||
|
|
@ -26,11 +26,11 @@ impl <T: Sync> RequiresShare for X<T> { }
|
|||
impl <T: Sync+Send> RequiresRequiresShareAndSend for X<T> { }
|
||||
|
||||
fn foo<T: RequiresRequiresShareAndSend>(val: T, chan: Sender<T>) {
|
||||
chan.send(val);
|
||||
chan.send(val).unwrap();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx): (Sender<X<int>>, Receiver<X<int>>) = channel();
|
||||
foo(X(31337i), tx);
|
||||
assert!(rx.recv() == X(31337i));
|
||||
assert!(rx.recv().unwrap() == X(31337i));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,18 @@
|
|||
// builtin-kinds, e.g., if a trait requires Send to implement, then
|
||||
// at usage site of that trait, we know we have the Send capability.
|
||||
|
||||
use std::comm::{channel, Sender, Receiver};
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
|
||||
trait Foo : Send { }
|
||||
|
||||
impl <T: Send> Foo for T { }
|
||||
|
||||
fn foo<T: Foo>(val: T, chan: Sender<T>) {
|
||||
chan.send(val);
|
||||
chan.send(val).unwrap();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx): (Sender<int>, Receiver<int>) = channel();
|
||||
foo(31337i, tx);
|
||||
assert!(rx.recv() == 31337i);
|
||||
assert!(rx.recv().unwrap() == 31337i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
// Tests the ability for the Self type in default methods to use
|
||||
// capabilities granted by builtin kinds as supertraits.
|
||||
|
||||
use std::comm::{Sender, channel};
|
||||
use std::sync::mpsc::{Sender, channel};
|
||||
|
||||
trait Foo : Send {
|
||||
fn foo(self, tx: Sender<Self>) {
|
||||
tx.send(self);
|
||||
tx.send(self).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -24,5 +24,5 @@ impl <T: Send> Foo for T { }
|
|||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
1193182i.foo(tx);
|
||||
assert!(rx.recv() == 1193182i);
|
||||
assert!(rx.recv().unwrap() == 1193182i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
extern crate log;
|
||||
|
||||
use log::{set_logger, Logger, LogRecord};
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::fmt;
|
||||
use std::io::{ChanReader, ChanWriter};
|
||||
use std::thread::Thread;
|
||||
|
|
|
|||
|
|
@ -16,5 +16,5 @@
|
|||
extern crate cci_capture_clause;
|
||||
|
||||
pub fn main() {
|
||||
cci_capture_clause::foo(()).recv()
|
||||
cci_capture_clause::foo(()).recv().unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
fn foo<F:FnOnce()+Send>(blk: F) {
|
||||
blk();
|
||||
|
|
@ -19,7 +19,7 @@ fn foo<F:FnOnce()+Send>(blk: F) {
|
|||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
foo(move || {
|
||||
tx.send(());
|
||||
tx.send(()).unwrap();
|
||||
});
|
||||
rx.recv();
|
||||
rx.recv().unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
let _t = task::spawn(move|| { child(&tx) });
|
||||
let y = rx.recv();
|
||||
let y = rx.recv().unwrap();
|
||||
println!("received");
|
||||
println!("{}", y);
|
||||
assert_eq!(y, 10);
|
||||
|
|
@ -22,6 +22,6 @@ pub fn main() {
|
|||
|
||||
fn child(c: &Sender<int>) {
|
||||
println!("sending");
|
||||
c.send(10);
|
||||
c.send(10).unwrap();
|
||||
println!("value sent");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ extern crate libc;
|
|||
use std::io::{Process, Command, timer};
|
||||
use std::time::Duration;
|
||||
use std::str;
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread::Thread;
|
||||
|
||||
macro_rules! succeed( ($e:expr) => (
|
||||
|
|
@ -88,13 +88,13 @@ pub fn test_destroy_actually_kills(force: bool) {
|
|||
let rx2 = t.oneshot(Duration::milliseconds(1000));
|
||||
Thread::spawn(move|| {
|
||||
select! {
|
||||
() = rx2.recv() => unsafe { libc::exit(1) },
|
||||
() = rx1.recv() => {}
|
||||
_ = rx2.recv() => unsafe { libc::exit(1) },
|
||||
_ = rx1.recv() => {}
|
||||
}
|
||||
}).detach();
|
||||
match p.wait().unwrap() {
|
||||
ExitStatus(..) => panic!("expected a signal"),
|
||||
ExitSignal(..) => tx.send(()),
|
||||
ExitSignal(..) => tx.send(()).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
#[deriving(PartialEq, Show)]
|
||||
enum Message {
|
||||
|
|
@ -23,7 +23,7 @@ struct SendOnDrop {
|
|||
|
||||
impl Drop for SendOnDrop {
|
||||
fn drop(&mut self) {
|
||||
self.sender.send(Message::Dropped);
|
||||
self.sender.send(Message::Dropped).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,10 +37,10 @@ impl Drop for Foo {
|
|||
fn drop(&mut self) {
|
||||
match self {
|
||||
&Foo::SimpleVariant(ref mut sender) => {
|
||||
sender.send(Message::DestructorRan);
|
||||
sender.send(Message::DestructorRan).unwrap();
|
||||
}
|
||||
&Foo::NestedVariant(_, _, ref mut sender) => {
|
||||
sender.send(Message::DestructorRan);
|
||||
sender.send(Message::DestructorRan).unwrap();
|
||||
}
|
||||
&Foo::FailingVariant { .. } => {
|
||||
panic!("Failed");
|
||||
|
|
@ -54,23 +54,23 @@ pub fn main() {
|
|||
{
|
||||
let v = Foo::SimpleVariant(sender);
|
||||
}
|
||||
assert_eq!(receiver.recv(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv_opt().ok(), None);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv().ok(), None);
|
||||
|
||||
let (sender, receiver) = channel();
|
||||
{
|
||||
let v = Foo::NestedVariant(box 42u, SendOnDrop { sender: sender.clone() }, sender);
|
||||
}
|
||||
assert_eq!(receiver.recv(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv(), Message::Dropped);
|
||||
assert_eq!(receiver.recv_opt().ok(), None);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
|
||||
assert_eq!(receiver.recv().ok(), None);
|
||||
|
||||
let (sender, receiver) = channel();
|
||||
task::spawn(move|| {
|
||||
let v = Foo::FailingVariant { on_drop: SendOnDrop { sender: sender } };
|
||||
});
|
||||
assert_eq!(receiver.recv(), Message::Dropped);
|
||||
assert_eq!(receiver.recv_opt().ok(), None);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
|
||||
assert_eq!(receiver.recv().ok(), None);
|
||||
|
||||
let (sender, receiver) = channel();
|
||||
{
|
||||
|
|
@ -83,11 +83,11 @@ pub fn main() {
|
|||
v = Foo::FailingVariant { on_drop: SendOnDrop { sender: sender } };
|
||||
});
|
||||
}
|
||||
assert_eq!(receiver.recv(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv(), Message::Dropped);
|
||||
assert_eq!(receiver.recv(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv(), Message::Dropped);
|
||||
assert_eq!(receiver.recv(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv(), Message::Dropped);
|
||||
assert_eq!(receiver.recv_opt().ok(), None);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::DestructorRan);
|
||||
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
|
||||
assert_eq!(receiver.recv().ok(), None);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub fn map(filename: String, emit: map_reduce::putter) {
|
|||
|
||||
mod map_reduce {
|
||||
use std::collections::HashMap;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::str;
|
||||
use std::task;
|
||||
|
||||
|
|
@ -50,16 +50,16 @@ mod map_reduce {
|
|||
}
|
||||
let (tx, rx) = channel();
|
||||
println!("sending find_reducer");
|
||||
ctrl.send(ctrl_proto::find_reducer(key.as_bytes().to_vec(), tx));
|
||||
ctrl.send(ctrl_proto::find_reducer(key.as_bytes().to_vec(), tx)).unwrap();
|
||||
println!("receiving");
|
||||
let c = rx.recv();
|
||||
let c = rx.recv().unwrap();
|
||||
println!("{}", c);
|
||||
im.insert(key, c);
|
||||
}
|
||||
|
||||
let ctrl_clone = ctrl.clone();
|
||||
::map(input, |a,b| emit(&mut intermediates, ctrl.clone(), a, b) );
|
||||
ctrl_clone.send(ctrl_proto::mapper_done);
|
||||
ctrl_clone.send(ctrl_proto::mapper_done).unwrap();
|
||||
}
|
||||
|
||||
pub fn map_reduce(inputs: Vec<String>) {
|
||||
|
|
@ -77,7 +77,7 @@ mod map_reduce {
|
|||
let mut num_mappers = inputs.len() as int;
|
||||
|
||||
while num_mappers > 0 {
|
||||
match rx.recv() {
|
||||
match rx.recv().unwrap() {
|
||||
ctrl_proto::mapper_done => { num_mappers -= 1; }
|
||||
ctrl_proto::find_reducer(k, cc) => {
|
||||
let mut c;
|
||||
|
|
@ -86,7 +86,7 @@ mod map_reduce {
|
|||
Some(&_c) => { c = _c; }
|
||||
None => { c = 0; }
|
||||
}
|
||||
cc.send(c);
|
||||
cc.send(c).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@
|
|||
// This test may not always fail, but it can be flaky if the race it used to
|
||||
// expose is still present.
|
||||
|
||||
use std::comm::{channel, Sender, Receiver};
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
use std::thread::Thread;
|
||||
|
||||
fn helper(rx: Receiver<Sender<()>>) {
|
||||
for tx in rx.iter() {
|
||||
let _ = tx.send_opt(());
|
||||
let _ = tx.send(());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -25,11 +25,11 @@ fn main() {
|
|||
let _t = Thread::spawn(move|| { helper(rx) }).detach();
|
||||
let (snd, rcv) = channel::<int>();
|
||||
for _ in range(1i, 100000i) {
|
||||
snd.send(1i);
|
||||
snd.send(1i).unwrap();
|
||||
let (tx2, rx2) = channel();
|
||||
tx.send(tx2);
|
||||
tx.send(tx2).unwrap();
|
||||
select! {
|
||||
() = rx2.recv() => (),
|
||||
_ = rx2.recv() => (),
|
||||
_ = rcv.recv() => ()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#![feature(default_type_params)]
|
||||
|
||||
use std::task;
|
||||
use std::comm::Sender;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::thunk::Invoke;
|
||||
|
||||
type RingBuffer = Vec<f64> ;
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::io::println;
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread::Thread;
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
|
||||
tx.send("hello, world");
|
||||
tx.send("hello, world").unwrap();
|
||||
|
||||
Thread::spawn(move|| {
|
||||
println(rx.recv());
|
||||
println(rx.recv().unwrap());
|
||||
}).join().ok().unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,15 +8,16 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread::Thread;
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel::<&'static str>();
|
||||
|
||||
task::spawn(move|| {
|
||||
assert_eq!(rx.recv(), "hello, world");
|
||||
let t = Thread::spawn(move|| {
|
||||
assert_eq!(rx.recv().unwrap(), "hello, world");
|
||||
});
|
||||
|
||||
tx.send("hello, world");
|
||||
tx.send("hello, world").unwrap();
|
||||
t.join().ok().unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::thread::Thread;
|
||||
use std::comm::{channel, Receiver};
|
||||
use std::sync::mpsc::{channel, Receiver};
|
||||
|
||||
fn periodical(n: int) -> Receiver<bool> {
|
||||
let (chan, port) = channel();
|
||||
Thread::spawn(move|| {
|
||||
loop {
|
||||
for _ in range(1, n) {
|
||||
match chan.send_opt(false) {
|
||||
match chan.send(false) {
|
||||
Ok(()) => {}
|
||||
Err(..) => break,
|
||||
}
|
||||
}
|
||||
match chan.send_opt(true) {
|
||||
match chan.send(true) {
|
||||
Ok(()) => {}
|
||||
Err(..) => break
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ fn integers() -> Receiver<int> {
|
|||
Thread::spawn(move|| {
|
||||
let mut i = 1;
|
||||
loop {
|
||||
match chan.send_opt(i) {
|
||||
match chan.send(i) {
|
||||
Ok(()) => {}
|
||||
Err(..) => break,
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ fn main() {
|
|||
let threes = periodical(3);
|
||||
let fives = periodical(5);
|
||||
for _ in range(1i, 100i) {
|
||||
match (ints.recv(), threes.recv(), fives.recv()) {
|
||||
match (ints.recv().unwrap(), threes.recv().unwrap(), fives.recv().unwrap()) {
|
||||
(_, true, true) => println!("FizzBuzz"),
|
||||
(_, true, false) => println!("Fizz"),
|
||||
(_, false, true) => println!("Buzz"),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::{mod, channel};
|
||||
use std::sync::mpsc::{TryRecvError, channel};
|
||||
use std::io::timer::Timer;
|
||||
use std::thread::Thread;
|
||||
use std::time::Duration;
|
||||
|
|
@ -18,13 +18,13 @@ pub fn main() {
|
|||
let _t = Thread::spawn(move||{
|
||||
let mut timer = Timer::new().unwrap();
|
||||
timer.sleep(Duration::milliseconds(10));
|
||||
tx.send(());
|
||||
tx.send(()).unwrap();
|
||||
});
|
||||
loop {
|
||||
match rx.try_recv() {
|
||||
Ok(()) => break,
|
||||
Err(comm::Empty) => {}
|
||||
Err(comm::Disconnected) => unreachable!()
|
||||
Err(TryRecvError::Empty) => {}
|
||||
Err(TryRecvError::Disconnected) => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
fn producer(tx: &Sender<Vec<u8>>) {
|
||||
tx.send(
|
||||
vec!(1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8,
|
||||
13u8));
|
||||
13u8)).unwrap();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
@ -23,5 +23,5 @@ pub fn main() {
|
|||
producer(&tx)
|
||||
});
|
||||
|
||||
let _data: Vec<u8> = rx.recv();
|
||||
let _data: Vec<u8> = rx.recv().unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#[phase(plugin,link)]
|
||||
extern crate log;
|
||||
|
||||
use std::comm::{channel, Sender, Receiver};
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
use std::thread::Thread;
|
||||
|
||||
pub struct ChannelLogger {
|
||||
|
|
@ -30,7 +30,7 @@ impl ChannelLogger {
|
|||
|
||||
impl log::Logger for ChannelLogger {
|
||||
fn log(&mut self, record: &log::LogRecord) {
|
||||
self.tx.send(format!("{}", record.args));
|
||||
self.tx.send(format!("{}", record.args)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,9 +49,9 @@ pub fn main() {
|
|||
info!("f1o");
|
||||
});
|
||||
|
||||
assert_eq!(rx.recv().as_slice(), "foo");
|
||||
assert_eq!(rx.recv().as_slice(), "foo bar");
|
||||
assert_eq!(rx.recv().as_slice(), "bar foo");
|
||||
assert_eq!(rx.recv().as_slice(), "f1o");
|
||||
assert!(rx.recv_opt().is_err());
|
||||
assert_eq!(rx.recv().unwrap().as_slice(), "foo");
|
||||
assert_eq!(rx.recv().unwrap().as_slice(), "foo bar");
|
||||
assert_eq!(rx.recv().unwrap().as_slice(), "bar foo");
|
||||
assert_eq!(rx.recv().unwrap().as_slice(), "f1o");
|
||||
assert!(rx.recv().is_err());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
struct test {
|
||||
f: int,
|
||||
|
|
@ -30,10 +30,10 @@ pub fn main() {
|
|||
|
||||
task::spawn(move|| {
|
||||
let (tx2, rx2) = channel();
|
||||
tx.send(tx2);
|
||||
tx.send(tx2).unwrap();
|
||||
|
||||
let _r = rx2.recv();
|
||||
let _r = rx2.recv().unwrap();
|
||||
});
|
||||
|
||||
rx.recv().send(test(42));
|
||||
rx.recv().unwrap().send(test(42)).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
// tests that ctrl's type gets inferred properly
|
||||
struct Command<K, V> {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// Test that a class with only sendable fields can be sent
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
struct foo {
|
||||
i: int,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
use std::task;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
type ctx = Sender<int>;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,27 +9,27 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
pub fn main() { test05(); }
|
||||
|
||||
fn test05_start(tx : &Sender<int>) {
|
||||
tx.send(10);
|
||||
tx.send(10).unwrap();
|
||||
println!("sent 10");
|
||||
tx.send(20);
|
||||
tx.send(20).unwrap();
|
||||
println!("sent 20");
|
||||
tx.send(30);
|
||||
tx.send(30).unwrap();
|
||||
println!("sent 30");
|
||||
}
|
||||
|
||||
fn test05() {
|
||||
let (tx, rx) = channel();
|
||||
task::spawn(move|| { test05_start(&tx) });
|
||||
let mut value: int = rx.recv();
|
||||
let mut value: int = rx.recv().unwrap();
|
||||
println!("{}", value);
|
||||
value = rx.recv();
|
||||
value = rx.recv().unwrap();
|
||||
println!("{}", value);
|
||||
value = rx.recv();
|
||||
value = rx.recv().unwrap();
|
||||
println!("{}", value);
|
||||
assert_eq!(value, 30);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,18 +9,18 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
fn start(tx: &Sender<Sender<String>>) {
|
||||
let (tx2, rx) = channel();
|
||||
tx.send(tx2);
|
||||
tx.send(tx2).unwrap();
|
||||
|
||||
let mut a;
|
||||
let mut b;
|
||||
a = rx.recv();
|
||||
a = rx.recv().unwrap();
|
||||
assert!(a == "A".to_string());
|
||||
println!("{}", a);
|
||||
b = rx.recv();
|
||||
b = rx.recv().unwrap();
|
||||
assert!(b == "B".to_string());
|
||||
println!("{}", b);
|
||||
}
|
||||
|
|
@ -29,8 +29,8 @@ pub fn main() {
|
|||
let (tx, rx) = channel();
|
||||
let _child = task::spawn(move|| { start(&tx) });
|
||||
|
||||
let mut c = rx.recv();
|
||||
c.send("A".to_string());
|
||||
c.send("B".to_string());
|
||||
let mut c = rx.recv().unwrap();
|
||||
c.send("A".to_string()).unwrap();
|
||||
c.send("B".to_string()).unwrap();
|
||||
task::deschedule();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::task;
|
||||
|
||||
fn start(tx: &Sender<Sender<int>>) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::task;
|
||||
|
||||
fn start(tx: &Sender<int>, start: int, number_of_messages: int) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::task;
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::task;
|
||||
|
||||
fn start(tx: &Sender<int>, i0: int) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::cmp;
|
||||
|
||||
// Tests of ports and channels on various types
|
||||
|
|
@ -17,9 +17,9 @@ fn test_rec() {
|
|||
|
||||
let (tx, rx) = channel();
|
||||
let r0: R = R {val0: 0, val1: 1u8, val2: '2'};
|
||||
tx.send(r0);
|
||||
tx.send(r0).unwrap();
|
||||
let mut r1: R;
|
||||
r1 = rx.recv();
|
||||
r1 = rx.recv().unwrap();
|
||||
assert_eq!(r1.val0, 0);
|
||||
assert_eq!(r1.val1, 1u8);
|
||||
assert_eq!(r1.val2, '2');
|
||||
|
|
@ -28,8 +28,8 @@ fn test_rec() {
|
|||
fn test_vec() {
|
||||
let (tx, rx) = channel();
|
||||
let v0: Vec<int> = vec!(0, 1, 2);
|
||||
tx.send(v0);
|
||||
let v1 = rx.recv();
|
||||
tx.send(v0).unwrap();
|
||||
let v1 = rx.recv().unwrap();
|
||||
assert_eq!(v1[0], 0);
|
||||
assert_eq!(v1[1], 1);
|
||||
assert_eq!(v1[2], 2);
|
||||
|
|
@ -38,8 +38,8 @@ fn test_vec() {
|
|||
fn test_str() {
|
||||
let (tx, rx) = channel();
|
||||
let s0 = "test".to_string();
|
||||
tx.send(s0);
|
||||
let s1 = rx.recv();
|
||||
tx.send(s0).unwrap();
|
||||
let s1 = rx.recv().unwrap();
|
||||
assert_eq!(s1.as_bytes()[0], 't' as u8);
|
||||
assert_eq!(s1.as_bytes()[1], 'e' as u8);
|
||||
assert_eq!(s1.as_bytes()[2], 's' as u8);
|
||||
|
|
@ -82,28 +82,28 @@ impl cmp::PartialEq for t {
|
|||
|
||||
fn test_tag() {
|
||||
let (tx, rx) = channel();
|
||||
tx.send(t::tag1);
|
||||
tx.send(t::tag2(10));
|
||||
tx.send(t::tag3(10, 11u8, 'A'));
|
||||
tx.send(t::tag1).unwrap();
|
||||
tx.send(t::tag2(10)).unwrap();
|
||||
tx.send(t::tag3(10, 11u8, 'A')).unwrap();
|
||||
let mut t1: t;
|
||||
t1 = rx.recv();
|
||||
t1 = rx.recv().unwrap();
|
||||
assert_eq!(t1, t::tag1);
|
||||
t1 = rx.recv();
|
||||
t1 = rx.recv().unwrap();
|
||||
assert_eq!(t1, t::tag2(10));
|
||||
t1 = rx.recv();
|
||||
t1 = rx.recv().unwrap();
|
||||
assert_eq!(t1, t::tag3(10, 11u8, 'A'));
|
||||
}
|
||||
|
||||
fn test_chan() {
|
||||
let (tx1, rx1) = channel();
|
||||
let (tx2, rx2) = channel();
|
||||
tx1.send(tx2);
|
||||
let tx2 = rx1.recv();
|
||||
tx1.send(tx2).unwrap();
|
||||
let tx2 = rx1.recv().unwrap();
|
||||
// Does the transmitted channel still work?
|
||||
|
||||
tx2.send(10);
|
||||
tx2.send(10).unwrap();
|
||||
let mut i: int;
|
||||
i = rx2.recv();
|
||||
i = rx2.recv().unwrap();
|
||||
assert_eq!(i, 10);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
// no-pretty-expanded FIXME #15189
|
||||
|
||||
use std::thread::Thread;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
pub fn main() { println!("===== WITHOUT THREADS ====="); test00(); }
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ fn test00_start(ch: &Sender<int>, message: int, count: int) {
|
|||
let mut i: int = 0;
|
||||
while i < count {
|
||||
println!("Sending Message");
|
||||
ch.send(message + 0);
|
||||
ch.send(message + 0).unwrap();
|
||||
i = i + 1;
|
||||
}
|
||||
println!("Ending test00_start");
|
||||
|
|
@ -54,7 +54,7 @@ fn test00() {
|
|||
for _r in results.iter() {
|
||||
i = 0;
|
||||
while i < number_of_messages {
|
||||
let value = rx.recv();
|
||||
let value = rx.recv().unwrap();
|
||||
sum += value;
|
||||
i = i + 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#![allow(dead_assignment)]
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
pub fn main() { test00(); }
|
||||
|
||||
|
|
@ -18,36 +18,36 @@ fn test00() {
|
|||
let mut r: int = 0;
|
||||
let mut sum: int = 0;
|
||||
let (tx, rx) = channel();
|
||||
tx.send(1);
|
||||
tx.send(2);
|
||||
tx.send(3);
|
||||
tx.send(4);
|
||||
r = rx.recv();
|
||||
tx.send(1).unwrap();
|
||||
tx.send(2).unwrap();
|
||||
tx.send(3).unwrap();
|
||||
tx.send(4).unwrap();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
println!("{}", r);
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
println!("{}", r);
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
println!("{}", r);
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
println!("{}", r);
|
||||
tx.send(5);
|
||||
tx.send(6);
|
||||
tx.send(7);
|
||||
tx.send(8);
|
||||
r = rx.recv();
|
||||
tx.send(5).unwrap();
|
||||
tx.send(6).unwrap();
|
||||
tx.send(7).unwrap();
|
||||
tx.send(8).unwrap();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
println!("{}", r);
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
println!("{}", r);
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
println!("{}", r);
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
println!("{}", r);
|
||||
assert_eq!(sum, 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
pub fn main() { test00(); }
|
||||
|
||||
|
|
@ -18,8 +18,8 @@ fn test00() {
|
|||
let (tx, rx) = channel();
|
||||
let number_of_messages: int = 1000;
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages { tx.send(i + 0); i += 1; }
|
||||
while i < number_of_messages { tx.send(i + 0).unwrap(); i += 1; }
|
||||
i = 0;
|
||||
while i < number_of_messages { sum += rx.recv(); i += 1; }
|
||||
while i < number_of_messages { sum += rx.recv().unwrap(); i += 1; }
|
||||
assert_eq!(sum, number_of_messages * (number_of_messages - 1) / 2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#![allow(dead_assignment)]
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
pub fn main() { test00(); }
|
||||
|
||||
|
|
@ -25,21 +25,21 @@ fn test00() {
|
|||
let number_of_messages: int = 1000;
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages {
|
||||
tx0.send(i + 0);
|
||||
tx1.send(i + 0);
|
||||
tx2.send(i + 0);
|
||||
tx3.send(i + 0);
|
||||
tx0.send(i + 0).unwrap();
|
||||
tx1.send(i + 0).unwrap();
|
||||
tx2.send(i + 0).unwrap();
|
||||
tx3.send(i + 0).unwrap();
|
||||
i += 1;
|
||||
}
|
||||
i = 0;
|
||||
while i < number_of_messages {
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
i += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#![allow(dead_assignment)]
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::task;
|
||||
|
||||
pub fn main() { test00(); }
|
||||
|
|
@ -18,7 +18,7 @@ pub fn main() { test00(); }
|
|||
fn test00_start(c: &Sender<int>, start: int,
|
||||
number_of_messages: int) {
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages { c.send(start + i); i += 1; }
|
||||
while i < number_of_messages { c.send(start + i).unwrap(); i += 1; }
|
||||
}
|
||||
|
||||
fn test00() {
|
||||
|
|
@ -46,13 +46,13 @@ fn test00() {
|
|||
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages {
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
r = rx.recv();
|
||||
r = rx.recv().unwrap();
|
||||
sum += r;
|
||||
i += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::thread::Thread;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
pub fn main() { test00(); }
|
||||
|
||||
fn test00_start(c: &Sender<int>, number_of_messages: int) {
|
||||
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).unwrap(); i += 1; }
|
||||
}
|
||||
|
||||
fn test00() {
|
||||
|
|
@ -30,7 +30,7 @@ fn test00() {
|
|||
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages {
|
||||
sum += rx.recv();
|
||||
sum += rx.recv().unwrap();
|
||||
println!("{}", r);
|
||||
i += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
// rustboot can't transmit nils across channels because they don't have
|
||||
// any size, but rustc currently can because they do have size. Whether
|
||||
// or not this is desirable I don't know, but here's a regression test.
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
tx.send(());
|
||||
let n: () = rx.recv();
|
||||
tx.send(()).unwrap();
|
||||
let n: () = rx.recv().unwrap();
|
||||
assert_eq!(n, ());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel::<uint>();
|
||||
|
|
@ -19,9 +19,9 @@ pub fn main() {
|
|||
|
||||
task::spawn(move || {
|
||||
let x_in_child = &(*x) as *const int as uint;
|
||||
tx.send(x_in_child);
|
||||
tx.send(x_in_child).unwrap();
|
||||
});
|
||||
|
||||
let x_in_child = rx.recv();
|
||||
let x_in_child = rx.recv().unwrap();
|
||||
assert_eq!(x_in_parent, x_in_child);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::io::{ChanReader, ChanWriter};
|
||||
use std::thread;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
// quite quickly and it takes a few seconds for the sockets to get
|
||||
// recycled.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::io::{TcpListener, Listener, Acceptor, EndOfFile, TcpStream};
|
||||
use std::sync::{atomic, Arc};
|
||||
use std::thread::Thread;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use std::io::net::tcp::*;
|
|||
use std::io::test::*;
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
#[cfg_attr(target_os = "freebsd", ignore)]
|
||||
fn eventual_timeout() {
|
||||
|
|
@ -37,10 +37,10 @@ fn eventual_timeout() {
|
|||
let (_tx2, rx2) = channel::<()>();
|
||||
std::task::spawn(move|| {
|
||||
let _l = TcpListener::bind(addr).unwrap().listen();
|
||||
tx1.send(());
|
||||
let _ = rx2.recv_opt();
|
||||
tx1.send(()).unwrap();
|
||||
let _ = rx2.recv();
|
||||
});
|
||||
rx1.recv();
|
||||
rx1.recv().unwrap();
|
||||
|
||||
let mut v = Vec::new();
|
||||
for _ in range(0u, 10000) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use std::io::{fs, TempDir};
|
|||
use std::io;
|
||||
use std::os;
|
||||
use std::task;
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
fn test_tempdir() {
|
||||
let path = {
|
||||
|
|
@ -39,11 +39,11 @@ fn test_rm_tempdir() {
|
|||
let (tx, rx) = channel();
|
||||
let f = move|:| -> () {
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
tx.send(tmp.path().clone());
|
||||
tx.send(tmp.path().clone()).unwrap();
|
||||
panic!("panic to unwind past `tmp`");
|
||||
};
|
||||
task::try(f);
|
||||
let path = rx.recv();
|
||||
let path = rx.recv().unwrap();
|
||||
assert!(!path.exists());
|
||||
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
|
|
@ -80,12 +80,12 @@ fn test_rm_tempdir_close() {
|
|||
let (tx, rx) = channel();
|
||||
let f = move|:| -> () {
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
tx.send(tmp.path().clone());
|
||||
tx.send(tmp.path().clone()).unwrap();
|
||||
tmp.close();
|
||||
panic!("panic when unwinding past `tmp`");
|
||||
};
|
||||
task::try(f);
|
||||
let path = rx.recv();
|
||||
let path = rx.recv().unwrap();
|
||||
assert!(!path.exists());
|
||||
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
// and shared between tasks as long as all types fulfill Send.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::task;
|
||||
|
||||
trait Pet {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
message.
|
||||
*/
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::task;
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
|
||||
fn child(tx: &Sender<Box<uint>>, i: uint) {
|
||||
tx.send(box i);
|
||||
tx.send(box i).unwrap();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
@ -29,7 +29,7 @@ pub fn main() {
|
|||
|
||||
let mut actual = 0u;
|
||||
for _ in range(0u, n) {
|
||||
let j = rx.recv();
|
||||
let j = rx.recv().unwrap();
|
||||
actual += *j;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::channel;
|
||||
use std::sync::mpsc::channel;
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
tx.send(box 100i);
|
||||
let v = rx.recv();
|
||||
tx.send(box 100i).unwrap();
|
||||
let v = rx.recv().unwrap();
|
||||
assert_eq!(v, box 100i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::comm::{channel, Sender};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::task;
|
||||
|
||||
struct complainer {
|
||||
|
|
@ -18,7 +18,7 @@ struct complainer {
|
|||
impl Drop for complainer {
|
||||
fn drop(&mut self) {
|
||||
println!("About to send!");
|
||||
self.tx.send(true);
|
||||
self.tx.send(true).unwrap();
|
||||
println!("Sent!");
|
||||
}
|
||||
}
|
||||
|
|
@ -39,5 +39,5 @@ pub fn main() {
|
|||
let (tx, rx) = channel();
|
||||
task::spawn(move|| f(tx.clone()));
|
||||
println!("hiiiiiiiii");
|
||||
assert!(rx.recv());
|
||||
assert!(rx.recv().unwrap());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue