pub struct Offload<T> { /* private fields */ }Expand description
The async form of a sync implementation: each call runs the sync method on tokio’s blocking pool, so the async side never blocks.
- A unary call costs one hop to the blocking pool and back.
- A reply stream is pulled on the blocking pool and handed over through
a channel that holds up to 16 items; dropping the stream stops the
pull: no
nextof the sync iterator starts after that, and one already running finishes. - An inbound stream reaches the sync method as an iterator whose
nextwaits on the blocking thread, so a bidirectional call can answer each request as it arrives.
A panic in the sync method becomes RuntimeCode::Panicked: the call fails,
or the stream ends with that item. The work starts when the future is
first polled; once started, dropping the future does not stop a call
that is already running on the blocking pool.
The plugin implements each <Service>Async for Offload<T> where T
implements <Service>Sync. The helpers below are associated functions
(Offload::call(&offload, …)), so they never hide a trait method of the
same name.
Implementations§
Source§impl<T> Offload<T>
impl<T> Offload<T>
Source§impl<T: Send + Sync + 'static> Offload<T>
impl<T: Send + Sync + 'static> Offload<T>
Sourcepub fn call<R, F>(
this: &Offload<T>,
call: F,
) -> impl Future<Output = Result<R, Error>> + Send + 'static
pub fn call<R, F>( this: &Offload<T>, call: F, ) -> impl Future<Output = Result<R, Error>> + Send + 'static
Run call on the blocking pool and return its result.
Sourcepub fn server_streaming<X, F>(
this: &Offload<T>,
call: F,
) -> impl Future<Output = Result<ChannelStream<Result<X, Error>>, Error>> + Send + 'static
pub fn server_streaming<X, F>( this: &Offload<T>, call: F, ) -> impl Future<Output = Result<ChannelStream<Result<X, Error>>, Error>> + Send + 'static
Run call, which returns a reply stream, on the blocking pool, and
pull that stream there.
Sourcepub fn client_streaming<S, X, R, F>(
this: &Offload<T>,
requests: S,
call: F,
) -> impl Future<Output = Result<R, Error>> + Send + 'static
pub fn client_streaming<S, X, R, F>( this: &Offload<T>, requests: S, call: F, ) -> impl Future<Output = Result<R, Error>> + Send + 'static
Run call on the blocking pool with requests as an iterator and
return its result.
Sourcepub fn bidirectional<S, X, Y, F>(
this: &Offload<T>,
requests: S,
call: F,
) -> impl Future<Output = Result<ChannelStream<Result<Y, Error>>, Error>> + Send + 'static
pub fn bidirectional<S, X, Y, F>( this: &Offload<T>, requests: S, call: F, ) -> impl Future<Output = Result<ChannelStream<Result<Y, Error>>, Error>> + Send + 'static
Run call on the blocking pool with requests as an iterator, and
pull the reply stream it returns there.