Skip to main content

Offload

Struct Offload 

Source
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 next of the sync iterator starts after that, and one already running finishes.
  • An inbound stream reaches the sync method as an iterator whose next waits 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>

Source

pub fn new(service: T, handle: Handle) -> Offload<T>

The async form of service, run on the blocking pool of the runtime behind handle.

Source

pub fn from_arc(service: Arc<T>, handle: Handle) -> Offload<T>

The async form of a shared service.

Source

pub fn get_ref(this: &Offload<T>) -> &T

The sync implementation.

Source§

impl<T: Send + Sync + 'static> Offload<T>

Source

pub fn call<R, F>( this: &Offload<T>, call: F, ) -> impl Future<Output = Result<R, Error>> + Send + 'static
where F: FnOnce(&T) -> Result<R, Error> + Send + 'static, R: Send + 'static,

Run call on the blocking pool and return its result.

Source

pub fn server_streaming<X, F>( this: &Offload<T>, call: F, ) -> impl Future<Output = Result<ChannelStream<Result<X, Error>>, Error>> + Send + 'static
where F: FnOnce(&T) -> Result<BoxIter<'static, Result<X, Error>>, Error> + Send + 'static, X: Send + 'static,

Run call, which returns a reply stream, on the blocking pool, and pull that stream there.

Source

pub fn client_streaming<S, X, R, F>( this: &Offload<T>, requests: S, call: F, ) -> impl Future<Output = Result<R, Error>> + Send + 'static
where S: Stream<Item = Result<X, Error>> + Send + 'static, X: Send + 'static, F: FnOnce(&T, BoxIter<'static, Result<X, Error>>) -> Result<R, Error> + Send + 'static, R: Send + 'static,

Run call on the blocking pool with requests as an iterator and return its result.

Source

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
where S: Stream<Item = Result<X, Error>> + Send + 'static, X: Send + 'static, Y: Send + 'static, F: FnOnce(&T, BoxIter<'static, Result<X, Error>>) -> Result<BoxIter<'static, 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.

Trait Implementations§

Source§

impl<T> Clone for Offload<T>

Source§

fn clone(&self) -> Offload<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Offload<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Forget for Offload<T>

§

impl<T> Freeze for Offload<T>
where Arc<T>: Freeze,

§

impl<T> Move for Offload<T>

§

impl<T> RefUnwindSafe for Offload<T>
where Arc<T>: RefUnwindSafe,

§

impl<T> Send for Offload<T>
where Arc<T>: Send,

§

impl<T> Sync for Offload<T>
where Arc<T>: Sync,

§

impl<T> Unpin for Offload<T>
where Arc<T>: Unpin,

§

impl<T> UnsafeUnpin for Offload<T>
where Arc<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Offload<T>
where Arc<T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.