pub struct OutboxWorker<S>where
S: OutboxStore,{ /* private fields */ }Expand description
Worker that polls the outbox in a loop and dispatches envelopes to their registered handlers.
Generic over any OutboxStore backend. The worker takes ownership
of the store and a registry mapping event_type to its
ErasedHandler, then [Self::start] spawns the polling task and
returns a [JoinHandle].
Implementations§
Source§impl<S> OutboxWorker<S>where
S: OutboxStore,
impl<S> OutboxWorker<S>where
S: OutboxStore,
Sourcepub fn new(
store: S,
handlers: HashMap<&'static str, Arc<dyn ErasedHandler>>,
config: OutboxWorkerConfig,
) -> Self
pub fn new( store: S, handlers: HashMap<&'static str, Arc<dyn ErasedHandler>>, config: OutboxWorkerConfig, ) -> Self
Build a new worker.
Sourcepub fn run(
self,
cancel: CancellationToken,
) -> Pin<Box<dyn Future<Output = Result<(), OutboxError>> + Send>>
pub fn run( self, cancel: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<(), OutboxError>> + Send>>
Returns the polling loop as a boxed Send future that the caller spawns.
The future resolves to Ok(()) once the supplied
CancellationToken is cancelled. Transient store errors are
logged via tracing and the loop continues. Typical usage:
ⓘ
let cancel = CancellationToken::new();
let join = tokio::spawn(worker.run(cancel.clone()));
// ...
cancel.cancel();
join.await??;The return type is boxed to work around a current Rust compiler limitation around HRTB inference on GATs (see rust-lang/rust#100013).
Auto Trait Implementations§
impl<S> !RefUnwindSafe for OutboxWorker<S>
impl<S> !UnwindSafe for OutboxWorker<S>
impl<S> Freeze for OutboxWorker<S>where
S: Freeze,
impl<S> Send for OutboxWorker<S>
impl<S> Sync for OutboxWorker<S>
impl<S> Unpin for OutboxWorker<S>where
S: Unpin,
impl<S> UnsafeUnpin for OutboxWorker<S>where
S: UnsafeUnpin,
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
Mutably borrows from an owned value. Read more