Struct std::task::TaskBuilder

pub struct TaskBuilder {
    opts: TaskOpts,
    gen_body: Option<~fn(v: ~fn()) -> ~fn()>,
    can_not_copy: Option<NonCopyable>,
    consumed: bool,
}

The task builder type.

Provides detailed control over the properties and behavior of new tasks.

Methods

impl TaskBuilder

fn unlinked(&mut self)

Decouple the child task's failure from the parent's. If either fails, the other will not be killed.

fn supervised(&mut self)

Unidirectionally link the child task's failure with the parent's. The child's failure will not kill the parent, but the parent's will kill the child.

fn linked(&mut self)

Link the child task's and parent task's failures. If either fails, the other will be killed.

fn watched(&mut self)

Cause the parent task to collect the child's exit status (and that of all transitively-watched grandchildren) before reporting its own.

fn unwatched(&mut self)

Allow the child task to outlive the parent task, at the possible cost of the parent reporting success even if the child task fails later.

fn indestructible(&mut self)

Cause the child task to ignore any kill signals received from linked failure. This optimizes context switching, at the possible expense of process hangs in the case of unexpected failure.

fn future_result(&mut self, blk: &fn(v: Port<TaskResult>))

Get a future representing the exit status of the task.

Taking the value of the future will block until the child task terminates. The future-receiving callback specified will be called before the task is spawned; as such, do not invoke .get() within the closure; rather, store it in an outer variable/list for later use.

Note that the future returning by this function is only useful for obtaining the value of the next task to be spawning with the builder. If additional tasks are spawned with the same builder then a new result future must be obtained prior to spawning each task.

Failure

Fails if a future_result was already set for this task.

fn name(&mut self, name: ~str)

Name the task-to-be. Currently the name is used for identification only in failure messages.

fn sched_mode(&mut self, mode: SchedMode)

Configure a custom scheduler mode for the task.

fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn())

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(&mut self, f: ~fn())

Creates and executes a new child task

Sets up a new task with its own call stack and schedules it to run the provided unique closure. The task has the properties and behavior specified by the task_builder.

Failure

When spawning into a new scheduler, the number of threads requested must be greater than zero.

fn spawn_with<A: Send>(&mut self, arg: A, f: ~fn(v: A))

Runs a task, while transferring ownership of one argument to the child.

fn try<T: Send>(&mut self, f: ~fn() -> T) -> Result<T, ()>

Execute a function in another task and return either the return value of the function or result::err.

Return value

If the function executed successfully then try returns result::ok containing the value returned by the function. If the function fails then try returns result::err containing nil.

Failure

Fails if a future_result was already set for this task.