pub struct Sidejob<Req, Reply> { /* private fields */ }Expand description
Handle to a sidejob actor.
Sidejob is cheap to clone: clones share the same underlying
channel and overload counter, so spreading the handle across
dispatcher tasks does not change the back-pressure semantics.
Implementations§
Source§impl<Req, Reply> Sidejob<Req, Reply>
impl<Req, Reply> Sidejob<Req, Reply>
Sourcepub fn spawn<F, Fut>(name: &'static str, capacity: usize, handler: F) -> Self
pub fn spawn<F, Fut>(name: &'static str, capacity: usize, handler: F) -> Self
Spawn a new sidejob actor.
name is recorded as the name label on
sidejob_overload_total and used in tracing log lines.
capacity is the maximum number of in-flight requests the
mailbox will hold before it starts rejecting submits with
SidejobError::Overloaded.
The handler is FnMut so callers may close over mutable
state; because the actor loop is serial, the handler is
called against one request at a time.
§Panics
Panics if capacity is zero. A zero-capacity sidejob would
reject every submit and is almost certainly a configuration
mistake.
Sourcepub async fn submit(&self, req: Req) -> Result<Reply, SidejobError>
pub async fn submit(&self, req: Req) -> Result<Reply, SidejobError>
Submit a request and await the handler’s reply.
Returns SidejobError::Overloaded immediately if the
mailbox is full, or SidejobError::Stopped if the actor
(or this specific request’s per-request task) has gone away
before producing a reply.
Sourcepub fn try_submit(&self, req: Req) -> Result<Receiver<Reply>, SidejobError>
pub fn try_submit(&self, req: Req) -> Result<Receiver<Reply>, SidejobError>
Submit a request without awaiting the reply.
On success the caller receives the oneshot::Receiver for
the reply and may await it (or drop it) at leisure. Like
Sidejob::submit, a full mailbox returns
SidejobError::Overloaded immediately.
Sourcepub fn full_failures(&self) -> u64
pub fn full_failures(&self) -> u64
Number of submits this handle has observed being rejected
with SidejobError::Overloaded over its entire lifetime.
Cloned handles share the same counter.
Trait Implementations§
Auto Trait Implementations§
impl<Req, Reply> Freeze for Sidejob<Req, Reply>
impl<Req, Reply> RefUnwindSafe for Sidejob<Req, Reply>
impl<Req, Reply> Send for Sidejob<Req, Reply>
impl<Req, Reply> Sync for Sidejob<Req, Reply>
impl<Req, Reply> Unpin for Sidejob<Req, Reply>
impl<Req, Reply> UnsafeUnpin for Sidejob<Req, Reply>
impl<Req, Reply> UnwindSafe for Sidejob<Req, Reply>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.