Skip to main content

CommandSource

Trait CommandSource 

Source
pub trait CommandSource: Send + Sync {
    type AckHandle: Send + Sync;

    // Required methods
    fn next<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Pulled<Self::AckHandle>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn ack<'life0, 'async_trait>(
        &'life0 self,
        handle: Self::AckHandle,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn nack<'life0, 'async_trait>(
        &'life0 self,
        handle: Self::AckHandle,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Pull-model command source.

next() returns:

  • Ok(Some(Pulled { outcome, ack })) — one pulled item. The caller inspects outcome (Claimed / AlreadyClaimed / RetryLater / Failed) and decides whether to call ack (commit the pull) or nack (redeliver). Both ack and nack are required exactly once per pulled item.
  • Ok(None) — the source is exhausted (local-mode playbook complete, mock source drained). Long-running sources (worker NATS) never return None in normal operation.
  • Err(e) — transient or terminal source error before any pull happened; the caller’s retry policy decides whether to call next() again.

§Lifecycle invariants

  1. Each Pulled.ack handle must be consumed exactly once via ack(handle) or nack(handle) before the next next() call in the same task. (Multiple concurrent next() calls are safe; each gets its own handle.)
  2. ack and nack are idempotent at the trait level — calling them multiple times on the same handle is undefined; the source impl may panic or treat the duplicate as a no-op.

Required Associated Types§

Source

type AckHandle: Send + Sync

Opaque ack handle returned alongside each pulled item. Source impls choose their own type:

  • NATS source uses async_nats::jetstream::Message.
  • Mock sources can use () or a counter.

Required Methods§

Source

fn next<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Option<Pulled<Self::AckHandle>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Pull one command from the source. See trait docs for return shape and lifecycle.

Source

fn ack<'life0, 'async_trait>( &'life0 self, handle: Self::AckHandle, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Acknowledge a pulled item (commit the pull; do not redeliver).

Source

fn nack<'life0, 'async_trait>( &'life0 self, handle: Self::AckHandle, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Negative-acknowledge a pulled item (redeliver per the source’s own policy).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§