use crate::fast::CompactString;
use std::{sync::Arc, time::Duration};
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum TsgoEvent {
JsonRpcRequestTimedOut {
method: CompactString,
timeout: Duration,
},
JsonRpcOutboundQueueFull,
JsonRpcPendingRequestsFailed { error: CompactString, count: usize },
MsgpackRequestTimedOut {
method: CompactString,
timeout: Duration,
},
MsgpackWorkerQueueFull { method: CompactString },
MsgpackWorkerTerminated { reason: CompactString },
OrchestratorSnapshotEvicted { key: CompactString },
OrchestratorResultEvicted { key: CompactString },
}
pub trait TsgoObserver: Send + Sync + 'static {
fn on_event(&self, event: &TsgoEvent);
}
pub type SharedObserver = Arc<dyn TsgoObserver>;
pub fn observe(observer: Option<&SharedObserver>, event: TsgoEvent) {
if let Some(observer) = observer {
observer.on_event(&event);
}
}