Skip to main content

actl_core/
wait_control.rs

1//! Scoped cancellation for workflow waits; never interrupts an in-flight COM call.
2use crate::{CtlError, ErrorCode, state::SignalPaths};
3use std::{cell::RefCell, marker::PhantomData, path::PathBuf, rc::Rc};
4
5thread_local! {
6    static PAUSE: RefCell<Option<PathBuf>> = const { RefCell::new(None) };
7}
8pub struct Scope(Option<PathBuf>, PhantomData<Rc<()>>);
9impl Scope {
10    pub fn enter(path: PathBuf) -> Self {
11        Self(PAUSE.with(|p| p.replace(Some(path))), PhantomData)
12    }
13}
14impl Drop for Scope {
15    fn drop(&mut self) {
16        PAUSE.with(|p| p.replace(self.0.take()));
17    }
18}
19pub fn check() -> Result<(), CtlError> {
20    PAUSE.with(|p| {
21        if let Some(path) = p.borrow().as_ref()
22            && (path.exists() || SignalPaths::default().stop_requested())
23        {
24            return Err(CtlError::new(
25                ErrorCode::Aborted,
26                "workflow wait interrupted",
27            ));
28        }
29        Ok(())
30    })
31}