Struct aspen::std_nodes::Action [] [src]

pub struct Action { /* fields omitted */ }

A node that manages the execution of tasks in a separate thread.

This node will launch the supplied function in a separate thread and ticks will monitor the state of that thread. If the supplied function returns true then the node is considered successful, otherwise it is considered to have failed.

This node should be the main way of modifying the world state. Note that most, in most cases, there will only be one thread modifying the world.

State

Initialized: Before being ticked after either being created or reset.

Running: While the function is being executed in the other thread.

Succeeded: When the function returns true.

Failed: When the function returns false.

Children

None.

Examples

An action node that attempts to subtract two unsigned integers:

const  FIRST:  usize = 10;
const  SECOND: usize = 100;
static result: AtomicUsize = ATOMIC_USIZE_INIT;

let mut action = Action::new(||{
    if FIRST < SECOND {
        result.store(SECOND - FIRST, Ordering::SeqCst);
        true
    } else { false }
});

// Run the node until it completes
while !action.tick().is_done() { };
assert_eq!(action.status(), Status::Succeeded);
assert_eq!(result.load(Ordering::SeqCst), 90);

Methods

impl Action
[src]

Creates a new Action node that will execute the given task.

Trait Implementations

impl Internals for Action
[src]

Ticks the internal state of the node a single time. Read more

Resets the internal state of this node.

If there is a task currently running, this will block until the task is completed.

Returns the constant string "Action"

Returns a vector of references to this node's children. Read more