use crate::{CommandError, Value};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
#[derive(Clone, Debug, PartialEq)]
pub struct Invocation {
pub command: usize,
pub params: Vec<Value>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CommandStatus {
Accepted,
Completed,
}
#[derive(Clone, Debug, PartialEq)]
pub struct CommandOutcome {
pub status: CommandStatus,
pub revision: u64,
pub result: Result<Value, CommandError>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct StateUpdate {
pub revision: u64,
pub changes: Vec<(usize, Value)>,
}
#[derive(Clone, Debug, Default)]
pub struct Cancellation(Arc<AtomicBool>);
impl Cancellation {
pub fn new() -> Self {
Self::default()
}
pub fn is_cancelled(&self) -> bool {
self.0.load(Ordering::Relaxed)
}
pub fn cancel(&self) {
self.0.store(true, Ordering::Relaxed);
}
}