Skip to content

cloacina-python::runtime_scope

Rust

Thread-local “current Runtime” slot used by Python decorators/loader.

CLOACI-T-0509 step 2: instead of pushing into the process-global task/workflow/trigger registries, Python registration paths resolve a scoped cloacina::Runtime via current_runtime. The caller (typically crate::runtime_impl::CloacinaPythonRuntime) installs a ScopedRuntime around the Python import so decorators see it.

pub

RAII guard that installs a Runtime into the thread-local slot for the duration of its lifetime. Errors on new if a runtime is already installed on this thread — nesting would silently corrupt the caller’s registration target.

pub

fn new(runtime: Arc<Runtime>) -> Result<Self, String>

Install runtime into the thread-local slot. Errors if another runtime is already installed on this thread.

Source
pub fn new(runtime: Arc<Runtime>) -> Result<Self, String> {
CURRENT_RUNTIME.with(|slot| {
let mut borrow = slot.borrow_mut();
if borrow.is_some() {
return Err(
"ScopedRuntime::new called while a Runtime is already installed on this thread"
.to_string(),
);
}
*borrow = Some(runtime);
Ok(())
})?;
Ok(Self { _private: () })
}

pub

fn current_runtime() -> Option<Arc<Runtime>>

Fetch the Runtime currently installed on this thread, if any.

Source
pub fn current_runtime() -> Option<Arc<Runtime>> {
CURRENT_RUNTIME.with(|slot| slot.borrow().clone())
}