-
Notifications
You must be signed in to change notification settings - Fork 625
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
Consider adding a fn to Sink
that can be used to check if the sink is ready to accept a value without actually sending one.
#409
Comments
I'd be ok adding this, but I think it's important to default to |
Ok, so you have to help me remember the conclusion we reached in Hawaii.. maybe @aturon has notes! So, it's important for poll_ready() in this case to not return any false positives (otherwise it defeats the purpose of avoiding storage). I also agree that ergonomics are important, so maybe the conclusion was that this shouldn't be a fn on Sink? Maybe it was a separate trade w/ some sort of combinator that provided poll_ready? |
Basically, you can always make any |
Here's what I have in my notes:
|
Thanks... now hopefully that jogs someones memory :P |
Hm so "like the fuse pattern" may imply:
(modulo all the naming conflicts I guess) |
So, after talking a bunch about this in IRC, the conclusion is that this is tricky.
The best option that came up was to introduce a new trait (naming TBD): trait ReadySink: Sink {
fn poll_ready(&mut self) -> Async<()>,
} The problem here is that, this is yet another trait to implement and all implementations of Sink / Stream now have to add and forward. This is getting a bit crazy. So, the exact strategy by which to introduce this is still TBD and will need more consideration. For the immediate, structs can implement |
Another question, should The behavior of
In which case, fn start_send(&mut self, item: Self::Item) -> StartSend<Self::SinkItem, Self::SinkError> {
if !try!(self.poll_ready()).is_ready() {
return Ok(AsyncSink::NotReady(item));
}
// Rest of the implementation
}
|
On the topic of false positives: In the "one way mapping" case, if |
Is there a known case? I'm sure there is, but nobody wrote it down! |
If we disallow false positives does that mean we allow false negatives? In other words, how would we impement |
Well, the mpsc channel type is able to guarantee that if |
Hm perhaps yeah. In general I feel like trying to disallow false positives is too strong of a guarantee we can provide here. IIRC we came up with a number of situations where such a guarantee would impose a cost to provide where it otherwise wouldn't be necessary. You can always write a wrapper which provides the guarantee, no? |
@alexcrichton well, the problem is that if Maybe the answer is if you can't guarantee no false positives, you don't implement |
@carllerche hm this is all sounds very familiar like we've discussed this a few times... This sounds, though, like a "fused iterator" style problem? |
That goes back to "The "fusing" feature is a nice to have, but is tricky as to how to implement." :) I'm not really sure what the "fused iterator" style would look like in this case. |
This happened in 0.2. |
I propose
Sink::poll_ready
(in part so this issue shows up in searches).I remember discussing this at the December 16 work week, but I don't entirely remember all the details. I didn't find another issue tracking this, so I am opening one (please close if this is a dup). This function can help in cases where it is useful to know if a
start_send
will succeed before creating the value. Imagine that storing the value is has a cost compared to generating & sending it immediately with no buffered storage.Relates to #256.
The text was updated successfully, but these errors were encountered: