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.