Struct std::task::TaskBuilder[src]
pub struct TaskBuilder<S = SiblingSpawner> {
// some fields omitted
}The task builder type.
Provides detailed control over the properties and behavior of new tasks.
Methods
impl TaskBuilder<SiblingSpawner>
fn new() -> TaskBuilder<SiblingSpawner>
Generate the base configuration for spawning a task, off of which more configuration methods can be chained.
impl<S: Spawner> TaskBuilder<S>
fn named<T: IntoMaybeOwned<'static>>(self, name: T) -> TaskBuilder<S>
Name the task-to-be. Currently the name is used for identification only in failure messages.
fn stack_size(self, size: uint) -> TaskBuilder<S>
Set the size of the stack for the new task.
fn stdout(self, stdout: Box<Writer + Send>) -> TaskBuilder<S>
Redirect task-local stdout.
fn stderr(self, stderr: Box<Writer + Send>) -> TaskBuilder<S>
Redirect task-local stderr.
fn spawner<T: Spawner>(self, spawner: T) -> TaskBuilder<T>
Set the spawning mechanism for the task.
The TaskBuilder API configures a task to be spawned, but defers to the
"spawner" to actually create and spawn the task. The spawner method
should not be called directly by TaskBuiler clients. It is intended
for use by downstream crates (like native and green) that implement
tasks. These downstream crates then add extension methods to the
builder, like .native() and .green(pool), that actually set the
spawner.
fn with_wrapper(self, wrapper: proc(v: proc(): Send): Send -> proc(): Send) -> TaskBuilder<S>
Add a wrapper to the body of the spawned task.
Before the task is spawned it is passed through a 'body generator' function that may perform local setup operations as well as wrap the task body in remote setup operations. With this the behavior of tasks can be extended in simple ways.
This function augments the current body generator with a new body generator by applying the task body which results from the existing body generator to the new body generator.
fn spawn(self, f: proc(): Send)
Creates and executes a new child task.
Sets up a new task with its own call stack and schedules it to run
the provided proc. The task has the properties and behavior
specified by the TaskBuilder.
fn try_future<T: Send>(self, f: proc(): Send -> T) -> Future<Result<T, Box<Any + Send>>>
Execute a proc in a newly-spawned task and return a future representing
the task's result. The task has the properties and behavior
specified by the TaskBuilder.
Taking the value of the future will block until the child task terminates.
Return value
If the child task executes successfully (without failing) then the
future returns result::Ok containing the value returned by the
function. If the child task fails then the future returns result::Err
containing the argument to fail!(...) as an Any trait object.
fn try<T: Send>(self, f: proc(): Send -> T) -> Result<T, Box<Any + Send>>
Execute a function in a newly-spawnedtask and block until the task
completes or fails. Equivalent to .try_future(f).unwrap().