alkstore 0.1.0

The alkstore contract crate: one reactive store trait surface — notify, streams, durable queues, TTL locks, outbox, scheduler — implemented by the alkstore-sqlite/-postgres/-mem engine crates; no driver dependencies
Documentation
//! The stop token (ADR-019 §4): core-owned, contract-visible handle
//! for `run_schedules(stop)`.
//!
//! The token is pinned in core because the parameter type is contract
//! surface (ADR-017 — a pinned method's signature); the *await
//! mechanics* are engine-internal (tokio watch per engine — engines
//! may wrap their own watch channels around this token). Core
//! implements the flip-everywhere semantics with a shared
//! `Arc<AtomicBool>`.

use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

/// A cloneable cancel handle for `run_schedules(stop)`.
///
/// `cancel()` on any clone flips every clone; the engine's
/// `run_schedules` ends its sleep early and returns `Ok(())` — the
/// clean-stop return (leadership loss still returns
/// `Err(LeadershipLost)` regardless of the token, ADR-009 §1).
#[derive(Clone)]
pub struct StopToken {
    cancelled: Arc<AtomicBool>,
}

impl StopToken {
    /// Create a fresh, uncancelled token.
    pub fn new() -> Self {
        StopToken {
            cancelled: Arc::new(AtomicBool::new(false)),
        }
    }

    /// Cancel the token — flips every clone (they share one flag).
    pub fn cancel(&self) {
        self.cancelled.store(true, Ordering::SeqCst);
    }

    /// Whether the token has been cancelled (by any clone).
    pub fn is_cancelled(&self) -> bool {
        self.cancelled.load(Ordering::SeqCst)
    }
}

impl Default for StopToken {
    fn default() -> Self {
        StopToken::new()
    }
}

impl std::fmt::Debug for StopToken {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("StopToken")
            .field("cancelled", &self.is_cancelled())
            .finish()
    }
}