actl-core 0.1.7

Protocol layer: JSON envelope, error codes, ref semantics (platform-free)
Documentation
//! Scoped cancellation for workflow waits; never interrupts an in-flight COM call.
use crate::{CtlError, ErrorCode};
use std::{cell::RefCell, marker::PhantomData, path::PathBuf, rc::Rc};

thread_local! {
    static PAUSE: RefCell<Option<PathBuf>> = const { RefCell::new(None) };
}
pub struct Scope(Option<PathBuf>, PhantomData<Rc<()>>);
impl Scope {
    pub fn enter(path: PathBuf) -> Self {
        Self(PAUSE.with(|p| p.replace(Some(path))), PhantomData)
    }
}
impl Drop for Scope {
    fn drop(&mut self) {
        PAUSE.with(|p| p.replace(self.0.take()));
    }
}
pub fn check() -> Result<(), CtlError> {
    crate::stop::check_current()?;
    PAUSE.with(|p| {
        if let Some(path) = p.borrow().as_ref()
            && path.exists()
        {
            return Err(CtlError::new(
                ErrorCode::Aborted,
                "workflow wait interrupted",
            ));
        }
        Ok(())
    })
}