-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync: Update broadcast::recv to return a named future #6908
base: master
Are you sure you want to change the base?
Conversation
Are you sure this actually allows you to solve #6902? The stream is still going to need to be self-referential. |
Well, I think it helps. My current plan for my downstream crate is to write a self-referential I can also think of two alternatives:
|
I don't love exposing future types because it makes the documentation worse. Right now, the function is documented as an By the way, tokio/tokio-util/src/sync/cancellation_token.rs Lines 79 to 98 in 28c9a14
(The ci failure is fixed on master.) |
Right, I agree about So, what would be your preferred solution here? I can go with whatever, including no changes to tokio at all (I have a working solution downstream already afterall, even though the reasoning around it being safe is a bit thin). |
We can add this. Please expose the future in |
Move from sync::broadcast to sync::futures.
I have implemented the changes you asked for. I haven't had any focus time for finishing the hand-written self-referential future based on this (what motivated me to write this PR). One thing I have already found is that the Given this uncertainty, I wouldn't mind if merging this PR was delayed until I finish the downstream work that needs this, though it could lead to bitrot. However you want to deal with this is fine by me. |
Inlining the coop logic into |
Motivation
Closes #6902.
Solution
I only made the minimal change of adding the public
Recv
future type.I also briefly looked into updating
tokio_stream::wrappers::BroadcastStream
to not useReusableBoxFuture
, but it's not as easy as I had hoped as it owns the underlying receiver while borrowing it when being polled - i.e. it's self-referential which is only possible withasync fn
or some extraunsafe
code.For my main use case for this though (in my own crate), the
unsafe
code +impl !Unpin
is likely preferable over the hack I shared in the issue linked above. I don't know whether the same applies totokio-stream
.