use dyn_clone::DynClone;
use crate::traits::{Algorithm, Status, Terminator};
use std::ops::ControlFlow;
pub trait AbortSignal: DynClone + Send + Sync {
fn is_aborted(&self) -> bool;
fn abort(&self);
fn reset(&self);
}
dyn_clone::clone_trait_object!(AbortSignal);
impl<T, A, P, S, U, E, C> Terminator<A, P, S, U, E, C> for T
where
T: AbortSignal,
A: Algorithm<P, S, U, E, Config = C>,
S: Status,
{
fn check_for_termination(
&mut self,
_current_step: usize,
_algorithm: &mut A,
_problem: &P,
_status: &mut S,
_args: &U,
_config: &C,
) -> ControlFlow<()> {
if self.is_aborted() {
self.reset();
return ControlFlow::Break(());
}
ControlFlow::Continue(())
}
}