A type representing values that may be computed concurrently and operations for working with them.
#### fn fib(n: uint) -> uint {42};
#### fn make_a_sandwich() {};
let mut delayed_fib = extra::future::spawn (|| fib(5000) );
make_a_sandwich();
println(fmt!("fib(5000) = %?", delayed_fib.get()))
Future
- The future typeof Drop for Future<A> where <A>
for Future<A> where <A: Copy>
- Methods on the future
typefor Future<A> where <A>
from_fn
- Create a future from a function.from_port
- Create a future from a portfrom_value
- Create a future from a value.spawn
- Create a future from a unique closure.Future
pub struct Future<A> {
priv state: FutureState<A>,
}
The future type
Drop
for Future<A>
where <A>
drop
fn drop(&self)
Future<A>
where <A: Copy>
Methods on the future
type
get
fn get(&mut self) -> A
Get the value of the future.
Future<A>
where <A>
get_ref
fn get_ref<'a>(&'a mut self) -> &'a A
Executes the future's closure and then returns a borrowed pointer to the result. The borrowed pointer lasts as long as the future.
from_fn
fn from_fn<A>(f: ~fn() -> A) -> Future<A>
Create a future from a function.
The first time that the value is requested it will be retrieved by calling the function. Note that this function is a local function. It is not spawned into another task.
from_port
fn from_port<A: Send>(port: PortOne<A>) -> Future<A>
Create a future from a port
The first time that the value is requested the task will block waiting for the result to be received on the port.
from_value
fn from_value<A>(val: A) -> Future<A>
Create a future from a value.
The value is immediately available and calling get
later will not block.
spawn
fn spawn<A: Send>(blk: ~fn() -> A) -> Future<A>
Create a future from a unique closure.
The closure will be run in a new task and its result used as the value of the future.