Skip to main content

Spawnable

Trait Spawnable 

Source
pub trait Spawnable: Send + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn registrations(&self) -> Vec<(SocketKind, TransportConfig)>;
    fn run(
        self: Box<Self>,
        shutdown: Arc<Notify>,
        on_ready: Option<Sender<()>>,
    ) -> Result<()>;
}
Expand description

Trait for services that can be spawned by ServiceSpawner.

Implemented by both REQ/REP handlers and XSUB/XPUB proxies. This provides a unified spawning API regardless of service type.

Required Methods§

Source

fn name(&self) -> &str

Service name (for logging and registry).

Source

fn registrations(&self) -> Vec<(SocketKind, TransportConfig)>

Endpoints to register with EndpointRegistry.

Each tuple is (SocketKind, TransportConfig).

  • Handlers typically register one REP endpoint
  • Proxies register PUB and SUB endpoints (note socket type inversion)
Source

fn run( self: Box<Self>, shutdown: Arc<Notify>, on_ready: Option<Sender<()>>, ) -> Result<()>

Run the service on current thread (blocking).

Called by spawner after thread/process setup. Should block until shutdown is signaled.

§Arguments
  • shutdown - Notification to signal service shutdown
  • on_ready - Optional oneshot sender to signal when socket is bound and ready

Implementors§

Source§

impl<S> Spawnable for QuicServiceLoop<S>
where S: RequestService + Send + Sync + 'static,

Source§

impl<S: RequestService + Send + Sync> Spawnable for S

Every RequestService + Send + Sync is automatically Spawnable.

This blanket implementation eliminates the need for wrapper types. Services that implement RequestService include their infrastructure (context, transport, verifying_key) and can be spawned directly.

Services not satisfying Send + Sync (e.g., those using Rc or !Send fields) must implement Spawnable directly (as InferenceServiceConfig does).