* ```
*/
-#[allow(missing_doc)];
+#![allow(missing_doc)]
-use std::util::replace;
+use std::mem::replace;
/// A type encapsulating the result of a computation which may not be complete
pub struct Future<A> {
- priv state: FutureState<A>,
+ state: FutureState<A>,
}
enum FutureState<A> {
- Pending(proc() -> A),
+ Pending(proc():Send -> A),
Evaluating,
Forced(A)
}
Future {state: Forced(val)}
}
- pub fn from_fn(f: proc() -> A) -> Future<A> {
+ pub fn from_fn(f: proc():Send -> A) -> Future<A> {
/*!
* Create a future from a function.
*
}
impl<A:Send> Future<A> {
- pub fn from_port(port: Port<A>) -> Future<A> {
+ pub fn from_receiver(rx: Receiver<A>) -> Future<A> {
/*!
* Create a future from a port
*
*/
Future::from_fn(proc() {
- port.recv()
+ rx.recv()
})
}
- pub fn spawn(blk: proc() -> A) -> Future<A> {
+ pub fn spawn(blk: proc():Send -> A) -> Future<A> {
/*!
* Create a future from a unique closure.
*
* value of the future.
*/
- let (port, chan) = Chan::new();
+ let (tx, rx) = channel();
spawn(proc() {
- chan.send(blk());
+ tx.send(blk());
});
- Future::from_port(port)
+ Future::from_receiver(rx)
}
}
#[test]
fn test_from_value() {
- let mut f = Future::from_value(~"snail");
- assert_eq!(f.get(), ~"snail");
+ let mut f = Future::from_value("snail".to_owned());
+ assert_eq!(f.get(), "snail".to_owned());
}
#[test]
- fn test_from_port() {
- let (po, ch) = Chan::new();
- ch.send(~"whale");
- let mut f = Future::from_port(po);
- assert_eq!(f.get(), ~"whale");
+ fn test_from_receiver() {
+ let (tx, rx) = channel();
+ tx.send("whale".to_owned());
+ let mut f = Future::from_receiver(rx);
+ assert_eq!(f.get(), "whale".to_owned());
}
#[test]
fn test_from_fn() {
- let mut f = Future::from_fn(proc() ~"brail");
- assert_eq!(f.get(), ~"brail");
+ let mut f = Future::from_fn(proc() "brail".to_owned());
+ assert_eq!(f.get(), "brail".to_owned());
}
#[test]
fn test_interface_get() {
- let mut f = Future::from_value(~"fail");
- assert_eq!(f.get(), ~"fail");
+ let mut f = Future::from_value("fail".to_owned());
+ assert_eq!(f.get(), "fail".to_owned());
}
#[test]
fn test_interface_unwrap() {
- let f = Future::from_value(~"fail");
- assert_eq!(f.unwrap(), ~"fail");
+ let f = Future::from_value("fail".to_owned());
+ assert_eq!(f.unwrap(), "fail".to_owned());
}
#[test]
#[test]
fn test_spawn() {
- let mut f = Future::spawn(proc() ~"bale");
- assert_eq!(f.get(), ~"bale");
+ let mut f = Future::spawn(proc() "bale".to_owned());
+ assert_eq!(f.get(), "bale".to_owned());
}
#[test]