A type representing values that may be computed concurrently and operations for working with them.
let delayed_fib = future::spawn {|| fib(5000) };
make_a_sandwich();
io::println(#fmt("fib(5000) = %?", delayed_fib.get()))
future
- The future typeextensions for future<A>
- Methods on the future
typefrom_fn
- Create a future from a function.from_port
- Create a future from a portfrom_value
- Create a future from a valueget
- Get the value of the futurespawn
- Create a future from a unique closure.with
- Work with the value without copying itfuture::future_pipe
future
The future type
future({mut v: either<@A, fn@() -> A>,})
extensions for future<A>
Methods on the future
type
get
fn get() -> A
Get the value of the future
with
fn with<B>(blk: fn(A) -> B) -> B
Work with the value without copying it
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 retreived 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: future_pipe::client::waiting<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.
get
fn get<A: copy>(future: future<A>) -> A
Get the value of the future
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.
with
fn with<A, B>(future: future<A>, blk: fn(A) -> B) -> B
Work with the value without copying it