Thread-safe promise and nodiscard - #20
Merged
Merged
Conversation
added 10 commits
February 19, 2026 13:19
…to not indicate that the API changed
…xchange into resolve/reject to skip the notification as well
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.
Changes to the Promise:
Cancellation is removed from the destructor, as it is unnecessary. The asynchronous operation is launched only in await_suspend, which always suspends the coroutine. Therefore the promise is stored in the coroutine state and cannot be destroyed until the coroutine resumes. We also disallow explicit cancellation because I don't know of any use case for it. The only remaining case is when the promise is destructed before it is awaited and therefore the launc operation started. This only happens if the user forgets to call co_await. To address this, I'm adding a nodiscard tag that introduces a compile-time warning.
Arbitrating the race between resolution and rejection using an atomic exchange. (first step of making it thread-safe)
Adds nodiscard annotations and a method for explicitly detaching the outermost coroutine that is called from a regular ROS callback where it is not awaited. Detaching simply means that the coroutine state is kept alive after the wrapper promise goes out of scope.
Other cleanups:
std::optional<Result>, is simpler albeit taking more space.