Struct aspen::std_nodes::UntilSuccess [] [src]

pub struct UntilSuccess { /* fields omitted */ }

A node that repeats its child until the child succeeds.

This node will return that it is running until the child succeeds. It can potentially have a finite reset limit. If the child ever returns that it succeeds, this node returns that it succeeds. If the limit is reached before the child succeeds, this node fails.

State

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

Running: While the child node has yet to succeed and it is below the reset limit.

Succeeded: Once the child node succeeds.

Failed: If the reset limit was reached before the child succeeded.

Children

One, which will be ticked or reset every time the UntilSuccess node is ticked or reset. The child may also be reset multiple times before the parent node is reset or completed.

Examples

A child that will be repeated infinitely until it succeeds (lifetime boilerplate will hopefully be fixed soon):

let a = Rc::new(Cell::new(0));
let b = a.clone();
let child = Condition::new(move || b.get() == 10 );
let mut node = UntilSuccess::new(child);

for _ in 0..10 {
    assert_eq!(node.tick(), Status::Running);
    a.set(a.get() + 1);
}

assert_eq!(node.tick(), Status::Succeeded);

An UntilSuccess node will fail if the child doesn't succeed within the limit:

let runs = 10;
let child = AlwaysFail::new();
let mut node = UntilSuccess::with_limit(child, runs);

// Minus one since our final assert is a run
for _ in 0..(runs - 1) {
    assert_eq!(node.tick(), Status::Running);
}

assert_eq!(node.tick(), Status::Failed);

Methods

impl UntilSuccess
[src]

Creates a new UntilSuccess node that will keep trying indefinitely.

Creates a new UntilSuccess node that will only retry a specific number of times.

limit is the number of times the node can be reset, not the number of times it can be run. A limit of one means the node can be run twice.

Trait Implementations

impl Internals for UntilSuccess
[src]

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

Resets the internal state of the node. Read more

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

Returns the string "UntilSuccess".