refactor: extract is_aborted helpers, DRY 16 call sites
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
//! Shared abort-flag checks.
|
||||
//!
|
||||
//! The two variants (Option<Arc<AtomicBool>> and bare AtomicBool) are
|
||||
//! used across the agent runtime, subagent, workflow engine, and provider.
|
||||
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Check whether an optional abort flag has been signalled.
|
||||
pub fn is_aborted(flag: &Option<Arc<AtomicBool>>) -> bool {
|
||||
flag.as_ref().is_some_and(|f| f.load(Ordering::SeqCst))
|
||||
}
|
||||
|
||||
/// Check whether a bare abort flag has been signalled.
|
||||
pub fn is_aborted_direct(flag: &AtomicBool) -> bool {
|
||||
flag.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
/// Check whether an optional borrowed abort flag has been signalled.
|
||||
///
|
||||
/// This variant handles the `Option<&AtomicBool>` pattern used in
|
||||
/// service/provider.rs where the flag is passed as a by-value optional
|
||||
/// reference rather than an `Arc`.
|
||||
pub fn is_aborted_ref(flag: Option<&AtomicBool>) -> bool {
|
||||
flag.is_some_and(|f| f.load(Ordering::SeqCst))
|
||||
}
|
||||
Reference in New Issue
Block a user