liminal-rs 0.12.0

A conversation-based messaging bus built on beamr
Documentation
//! Who hears that a channel's subscriber left without an explicit unsubscribe.

use std::sync::{Arc, OnceLock};

use crate::channel::observer::ClusterObserver;

/// The supervisor's cluster observer, read when a departure happens (so an
/// observer installed after the channel started still hears it), and the
/// channel's name to report the departure under.
#[derive(Debug)]
pub struct Departures {
    /// The channel's name.
    pub channel: String,
    /// The supervisor's observer cell, shared.
    pub observer: Arc<OnceLock<Arc<dyn ClusterObserver>>>,
}

impl Departures {
    /// Tells the observer, if one is installed, that `pid` left the channel.
    pub fn report(&self, pid: u64) {
        if let Some(observer) = self.observer.get() {
            observer.on_unsubscribe(&self.channel, pid);
        }
    }
}