Skip to content

race and short circuit on first completion - #51

Merged
Sollimann merged 9 commits into
Sollimann:mainfrom
utahrobotics:main
Mar 17, 2026
Merged

race and short circuit on first completion#51
Sollimann merged 9 commits into
Sollimann:mainfrom
utahrobotics:main

Conversation

@matthewashton-k

Copy link
Copy Markdown
Collaborator

Thanks for your work on this crate, I've been loving using it for robotics recently!

I recently was trying to make a timeout behavior and realized that:

  • WhenAny - races children in parallel but short-circuits on first Success (ignores failures until all fail)
  • WhenAll - races children in parallel but short-circuits on first Failure
  • No node short-circuits on first completion regardless of success/failure

I think it would be helpful to have a node that runs things in parallel and take the result of whichever finishes first so you can do stuff like this:

/// fails if the behavior doesnt finish before the timer is up.
fn with_timeout<A: Clone>(behavior: Behavior<A>, timeout: f64) -> Behavior<A> {
    Race(vec![
        behavior,
        Invert(Box::new(Wait(timeout))),
    ])
}

You can achieve a similar thing with a while loop but the caveat is that if the inner behavior suceeds before the timer is up itll restart.

Of course ways to use the blackboard to do timeouts without adding a new node but I think this one might be helpful.

@Sollimann Sollimann self-assigned this Mar 8, 2026
@Sollimann Sollimann added the enhancement New feature or request label Mar 8, 2026
@Sollimann

Sollimann commented Mar 8, 2026

Copy link
Copy Markdown
Owner

Hey @matthewashton-k , thanks for contributing! Sorry for delay, I haven't paid attention to my notifications lately and this PR was lost in my inbox

The Race node fills a real gap in the behavior primitives, and test coverage is good. Before merging this please run pre-commit to fix the CI check, bump crate version to v0.11.0, update the README with an explanation of the new behavior, please include the behavior in an existing example in the examples/ folder or create a new one.

Sending you an invite to collaborate on the project, just decline the offer if you're not interested. If interested I'll make sure to update the Kanban board for the project and you can pick whatever tickets there you'd like and/or add new once.

The philosophy for the crate is to keep it as lean with as few external dependencies as possible (I really need to add a CONTRIBUTING.md file now that I think of it). Only add new node types if they behavior cannot be created already with the existing primitives (Race is a good addition)

@Sollimann

Copy link
Copy Markdown
Owner

Updated Kanban now: Bonsai Kanban

@matthewashton-k

Copy link
Copy Markdown
Collaborator Author

Awesome thanks!

I'll run the checks, make example, etc tomorrow and hopefully get that merged in.

@matthewashton-k

Copy link
Copy Markdown
Collaborator Author

ok the pre commit pipeline seems to be broken for some reason but ive ran it locally to make sure the clippy lints are fixed.

Error: getCacheEntry failed: <h2>Our services aren't available right now</h2><p>We're working to restore all services as soon as possible. Please check back soon.</p>0uimzaQAAAABP7DiB05vtRYOu/AzQNQuoQ0hJMzBFREdFMDMwOQBFZGdl

@matthewashton-k

Copy link
Copy Markdown
Collaborator Author

I also accepted the collaborator invitation but it looks like I still may not have the permissions to view the kanban board in the github project.

Anyways, I've added an example for the new Race behavior and this PR should be good to get merged in!

@Sollimann Sollimann left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, last thing before merging this. Please add a short note the Race behavior here as well

Image

Also, please bump the version to 0.11.0 here

version = "0.10.0"

@Sollimann

Copy link
Copy Markdown
Owner

Was not able to checkout your branch to fix as it comes from a fork. It probably just requires bumping to latest version of this action https://github.com/pre-commit/action in the workflow. Please check if that works, if not, we can fix the pre-commits in a separate PR

@Sollimann

Copy link
Copy Markdown
Owner

Just gave you RW access to Kanban now

@Sollimann Sollimann left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Sollimann
Sollimann merged commit cf9c749 into Sollimann:main Mar 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants