De-mode core::future.
This commit is contained in:
parent
bc6eaf2acb
commit
36883186ab
5 changed files with 25 additions and 21 deletions
|
|
@ -1,3 +1,7 @@
|
|||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
/*!
|
||||
* A type representing values that may be computed concurrently and
|
||||
* operations for working with them.
|
||||
|
|
@ -37,13 +41,13 @@ impl<A:copy send> future<A> {
|
|||
fn get() -> A {
|
||||
//! Get the value of the future
|
||||
|
||||
get(self)
|
||||
get(&self)
|
||||
}
|
||||
|
||||
fn with<B>(blk: fn(A) -> B) -> B {
|
||||
fn with<B>(blk: fn((&A)) -> B) -> B {
|
||||
//! Work with the value without copying it
|
||||
|
||||
with(self, blk)
|
||||
with(&self, blk)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +68,7 @@ macro_rules! move_it {
|
|||
{$x:expr} => { unsafe { let y <- *ptr::addr_of($x); y } }
|
||||
}
|
||||
|
||||
fn from_port<A:send>(-port: future_pipe::client::waiting<A>) -> future<A> {
|
||||
fn from_port<A:send>(+port: future_pipe::client::waiting<A>) -> future<A> {
|
||||
#[doc = "
|
||||
Create a future from a port
|
||||
|
||||
|
|
@ -110,13 +114,13 @@ fn spawn<A:send>(+blk: fn~() -> A) -> future<A> {
|
|||
}))
|
||||
}
|
||||
|
||||
fn get<A:copy>(future: future<A>) -> A {
|
||||
fn get<A:copy>(future: &future<A>) -> A {
|
||||
//! Get the value of the future
|
||||
|
||||
do with(future) |v| { v }
|
||||
do with(future) |v| { *v }
|
||||
}
|
||||
|
||||
fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B {
|
||||
fn with<A,B>(future: &future<A>, blk: fn((&A)) -> B) -> B {
|
||||
//! Work with the value without copying it
|
||||
|
||||
let v = match copy future.v {
|
||||
|
|
@ -127,7 +131,7 @@ fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B {
|
|||
v
|
||||
}
|
||||
};
|
||||
blk(*v)
|
||||
blk(v)
|
||||
}
|
||||
|
||||
proto! future_pipe {
|
||||
|
|
@ -139,7 +143,7 @@ proto! future_pipe {
|
|||
#[test]
|
||||
fn test_from_value() {
|
||||
let f = from_value(~"snail");
|
||||
assert get(f) == ~"snail";
|
||||
assert get(&f) == ~"snail";
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -147,14 +151,14 @@ fn test_from_port() {
|
|||
let (po, ch) = future_pipe::init();
|
||||
future_pipe::server::completed(ch, ~"whale");
|
||||
let f = from_port(po);
|
||||
assert get(f) == ~"whale";
|
||||
assert get(&f) == ~"whale";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_fn() {
|
||||
let f = fn@() -> ~str { ~"brail" };
|
||||
let f = from_fn(f);
|
||||
assert get(f) == ~"brail";
|
||||
assert get(&f) == ~"brail";
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -166,19 +170,19 @@ fn test_interface_get() {
|
|||
#[test]
|
||||
fn test_with() {
|
||||
let f = from_value(~"nail");
|
||||
assert with(f, |v| v) == ~"nail";
|
||||
assert with(&f, |v| *v) == ~"nail";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_interface_with() {
|
||||
let f = from_value(~"kale");
|
||||
assert f.with(|v| v) == ~"kale";
|
||||
assert f.with(|v| *v) == ~"kale";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_spawn() {
|
||||
let f = spawn(|| ~"bale");
|
||||
assert get(f) == ~"bale";
|
||||
assert get(&f) == ~"bale";
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -186,5 +190,5 @@ fn test_spawn() {
|
|||
#[ignore(cfg(target_os = "win32"))]
|
||||
fn test_futurefail() {
|
||||
let f = spawn(|| fail);
|
||||
let _x: ~str = get(f);
|
||||
let _x: ~str = get(&f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ impl task_builder {
|
|||
do self.future_result(|+r| { result = some(r); }).spawn {
|
||||
comm::send(ch, f());
|
||||
}
|
||||
match future::get(option::unwrap(result)) {
|
||||
match future::get(&option::unwrap(result)) {
|
||||
success => result::ok(comm::recv(po)),
|
||||
failure => result::err(())
|
||||
}
|
||||
|
|
@ -1704,13 +1704,13 @@ fn test_add_wrapper() {
|
|||
fn test_future_result() {
|
||||
let mut result = none;
|
||||
do task().future_result(|+r| { result = some(r); }).spawn { }
|
||||
assert future::get(option::unwrap(result)) == success;
|
||||
assert future::get(&option::unwrap(result)) == success;
|
||||
|
||||
result = none;
|
||||
do task().future_result(|+r| { result = some(r); }).unlinked().spawn {
|
||||
fail;
|
||||
}
|
||||
assert future::get(option::unwrap(result)) == failure;
|
||||
assert future::get(&option::unwrap(result)) == failure;
|
||||
}
|
||||
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
// Wait for children to pass their asserts
|
||||
for vec::each(children) |r| { future::get(r); }
|
||||
for vec::each(children) |r| { future::get(&r); }
|
||||
// Wait for writer to finish
|
||||
p.recv();
|
||||
do arc.read |num| { assert *num == 10; }
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ fn run_test(+test: test_desc, monitor_ch: comm::chan<monitor_msg>) {
|
|||
task::task().unlinked().future_result(|+r| {
|
||||
result_future = some(r);
|
||||
}).spawn(testfn);
|
||||
let task_result = future::get(option::unwrap(result_future));
|
||||
let task_result = future::get(&option::unwrap(result_future));
|
||||
let test_result = calc_result(test, task_result == task::success);
|
||||
comm::send(monitor_ch, (copy test, test_result));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ fn future_writer_factory(
|
|||
do task::spawn {
|
||||
let (writer, future) = future_writer();
|
||||
comm::send(writer_ch, writer);
|
||||
let s = future::get(future);
|
||||
let s = future::get(&future);
|
||||
comm::send(markdown_ch, (page, s));
|
||||
}
|
||||
comm::recv(writer_po)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue