[−][src]Struct plumbing::Pipeline
A Pipeline
manages sending requests through a stream and retrieving their
matching responses.
A pipeline manages request/response flow through a Sink
and associated
Stream
. The two halves should be set up such that:
- Items sent into the
Sink
are submitted to some underlying system as requests. - That system replies to each request with a response, in order, via the
Stream
.
This could be HTTP requests sent through a Keep-Alive
connection, Redis
interactions through the Redis Protocol, or anything else.
The Pipeline
provides a submit
method, which
submits a request. Pipelines are backpressure sensitive, so this method
will block until the underlying Sink
can accept it. Pipelines do not do
any extra buffering, so if you're using it to enqueue several requests at
once, be sure that the Sink
has been set up with its own buffering.
The submit
method will return a Resolver
associated with that request. This Resolver
is a future which will, when
awaited, resolve to the response associated with the Request. These
resolvers must be awaited or dropped in order to consume responses from the
underlying stream; be sure to set up concurrency or buffering to ensure
your request submissions don't get stuck because the system is waiting for
a response to be collected.
Implementations
impl<Si: Unpin, St: Unpin + Stream> Pipeline<Si, St>
[src]
pub fn new<T>(requests: Si, responses: St) -> Self where
Si: Sink<T>,
[src]
Si: Sink<T>,
Construct a new Pipeline
with associated channels for requests and
responses. In order for the Pipeline's logic to function correctly,
this pair must be set up such that each request submitted through
requests
eventually results in a response
being sent back through
responses
, in order.
pub async fn submit<T, '_>(
&'_ mut self,
item: T
) -> Result<Resolver<St>, Si::Error> where
Si: Sink<T>,
[src]
&'_ mut self,
item: T
) -> Result<Resolver<St>, Si::Error> where
Si: Sink<T>,
Submit a request to this Pipeline
, blocking until it can be sent to
the underlying Sink
. Returns a Resolver
that can be used to
await the response, or an error if the Sink
returned an error.
pub async fn submit_owned<T>(
__arg0: Self,
item: T
) -> (Self, Result<Resolver<St>, Si::Error>) where
Si: Sink<T>,
[src]
__arg0: Self,
item: T
) -> (Self, Result<Resolver<St>, Si::Error>) where
Si: Sink<T>,
impl<Si: Unpin, St> Pipeline<Si, St>
[src]
pub async fn flush<'a, T, '_>(&'_ mut self) -> Result<(), Si::Error> where
Si: Sink<T>,
[src]
Si: Sink<T>,
Flush the underlying Sink
, blocking until it's finished. Note that,
depending on your request/response system, you may also need to be sure
that any incomplete Resolvers
are also being awaited so that the
responses can be drained; this method only handles flushing the
requests side.
impl<Si, St: Stream> Pipeline<Si, St>
[src]
pub async fn finish(self) -> (Si, Option<Skip<St>>)
[src]
Finish the pipeline. Wait for all the Resolvers to complete (or abort), then return the original sink & stream. If the stream completed during the resolvers, return None instead of the stream.
This function returns a Skip<St>
so that any responses associated
with aborted Resolvers will be skipped.
Trait Implementations
Auto Trait Implementations
impl<Si, St> !RefUnwindSafe for Pipeline<Si, St>
impl<Si, St> Send for Pipeline<Si, St> where
Si: Send,
St: Send,
Si: Send,
St: Send,
impl<Si, St> Sync for Pipeline<Si, St> where
Si: Sync,
St: Send,
Si: Sync,
St: Send,
impl<Si, St> Unpin for Pipeline<Si, St> where
Si: Unpin,
Si: Unpin,
impl<Si, St> !UnwindSafe for Pipeline<Si, St>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,