proof of concept: replace select! with join_me_maybe::join!#1
Draft
oconnor663 wants to merge 3 commits into
Draft
proof of concept: replace select! with join_me_maybe::join!#1oconnor663 wants to merge 3 commits into
select! with join_me_maybe::join!#1oconnor663 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec5716f9f1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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.
This PR (internal to my clone, not upstream) is a proof of concept that
join_me_maybe::joincan replaceselect!loops in nontrivial cases. There are some scattered changes that go against the grain of surrounding code, and it would need a fair bit of cleanup if it was going to be seriously reviewed, but the goal here is just showing (myself) that it's possible to get it compiling and passing tests. This required adding several features tojoin_me_maybealong the way, and it was a useful forcing function.My motivation was this post by @nikomatsakis: https://smallcultfollowing.com/babysteps/blog/2022/06/13/async-cancellation-a-case-study-of-pub-sub-in-mini-redis. The thesis is that
select!is error-prone, and it would be nice to replace it in common use cases, but it also has some superpowers that make it hard to replace.select!arms get lowered to amatchin the calling function, which means they can mutate the same variables, and they can also short-circuit withreturnor?. Since an arm body doesn't run untilselect!has dropped all the "scrutinee" futures, borrows in the bodies don't conflict with those futures either. At the same time, for better or worse, it's also possible to.awaitasync function calls in the bodies.join_me_maybeapproaches this with several similar features:match, as inselect!. That means that only one body can run at a time. However, to avoid deadlocks, the bodies (whichever one is running at any given time) are still concurrent with all the "scrutinee" futures. (It's ajoin!rather than aselect!, so by default we wait for all of them.)?works. This requires some aggressive macro shenanigans, because each body can also evaluate to a value "the normal way" (though we don't use that in this case).join_me_maybedocs. This is the most complicated bit, and the most likely to change in future versions ofjoin_me_maybe. For each labeled future or stream, there's a "canceller" in scope, and it supports awith_mutmethod that exposes the labeled future/stream for mutation. That's what lets us add work to theStreamMapover time. Though see theTODOabove that join arm.