-
Notifications
You must be signed in to change notification settings - Fork 653
Support for back-pressurized, partially consuming Sink #1327
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
Comments
I think you can accomplish something similar with 0.3 Sinks by having an internal field to stage the buffer in your Sink impl. Then you return Ready only when the staging field has been fully written and can be replaced. |
@tikue The Sink impl still has to internalize or borrow the entire buffer, and there is a forced "pipeline break" where a partially consuming API could enable filling up the input buffer as it gets consumed by the writer. I think a solution with 0.3 may need a special adapter or a trait. |
@mzabaluev I think I'm imagining this differently. In the case of Bytes, a value of type Bytes is a fixed size regardless of the size of the backing buffer on the heap. So a Sink should always be able to internally buffer the whole Bytes value. |
I think that use-case is very special, and other Traits (e.g. |
@Matthias247 I agree in general. |
See also #1665, which currently includes an external implementation of a |
I don't have any planned changes related to this, and there hasn't been any discussion for over a year so i'm going to close this, but feel free to comment and I can reopen for discussion if there's a concrete proposal for improving the existing traits. |
There may be a case for
Sink
implementations that can consume their items partially as internal capacity allows. A simple example is a buffered write adapter that acceptsBytes
or slice items. In futures 0.1,start_send
for such a sink could process a leading part of the slice that fills the output buffer, and return the remaining part inAsyncSink::NotReady
. It is not implied by the documentation that the returned item might not be the same as the one passed intostart_send
, but technically there is nothing wrong with such an implementation, and it could be retroactively sanctioned.In the 0.3 API under development, the signature of
start_send
does not allow returning the item, and ready/not ready decision making is separated in thepoll_ready
method which must operate solely on internal state of the receiver. While this simple and clean design may be meant to remove ambiguities like the one described above, I wonder if the use case allowing more flexible utilization of data buffers, or any likewise divisible data, was consciously discarded.The text was updated successfully, but these errors were encountered: