Conversation
tzcnt
added a commit
that referenced
this pull request
Jun 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
tmc::select()free function works similarly to theselectstatement in Rust (tokio) or Go:Accepts a variadic list of
tmc::cancellable, which is a pair type that holds an awaitable operation (the Op) and a canceller for it. There are 3 overloads of thetmc::cancellableconstructor. Each receives an Op as the first parameter, but the canceller parameter is different:tmc::cancellableconstructor overload 1's canceller can be:tmc::cancellableconstructor overload 2's canceller can be:.cancel()method that cancels the Op when invoked (sync cancel).cancel()method that returns an awaitable, that when awaited, cancels the Op (async cancel)tmc::cancellableconstructor overload 3 receives a single object parameter that is both awaitable as the Op and exposes acancel()method that either:If multiple awaitables complete simultaneously, the winning result is biased toward the awaitable with the lower index (leftmost parameter).
After the losing operations are cancelled, it waits for them all to complete before returning. This is required for safety because operations in TMC borrow storage from their awaiting coroutine. This also means that you can provide a canceller that does nothing - it'll just wait for that awaitable to complete normally before discarding its result.
This flexible construction allows creating cancellations for a variety of awaitables. For example, you can implement cancellation for CPU-bound work by setting an atomic flag that's checked inside of a loop.
Documentation: https://www.fleetcode.com/oss/tmc/docs/dev/awaitables/select.html