weavegraph 0.7.0

Graph-driven, concurrent agent workflow framework with versioned state, deterministic barrier merges, and rich diagnostics.
Documentation
//! [`EventEmitter`] trait and [`EmitterError`] for publishing events to the bus.

use std::fmt::Debug;

use thiserror::Error;

use super::event::Event;

/// Synchronous, non-blocking event publisher injected into workflow nodes.
pub trait EventEmitter: Send + Sync + Debug {
    /// Publish an event.
    fn emit(&self, event: Event) -> Result<(), EmitterError>;
}

/// Error returned when event emission fails.
#[derive(Debug, Error)]
#[cfg_attr(feature = "diagnostics", derive(miette::Diagnostic))]
pub enum EmitterError {
    /// The event hub has been shut down.
    #[error("event hub closed")]
    #[cfg_attr(
        feature = "diagnostics",
        diagnostic(
            code(weavegraph::emitter::emitter_fail),
            help("Check event emitter configuration and downstream handler.")
        )
    )]
    Closed,
    /// Event emission failed for a reason other than hub closure.
    #[error("event emission failed: {0}")]
    #[cfg_attr(
        feature = "diagnostics",
        diagnostic(
            code(weavegraph::emitter::emitter_fail),
            help("Check event emitter configuration and downstream handler.")
        )
    )]
    Other(String),
}

impl EmitterError {
    /// Construct an [`EmitterError::Other`] from any string-like error message.
    pub fn other(msg: impl Into<String>) -> Self {
        Self::Other(msg.into())
    }
}