use std::collections::HashMap;
use std::sync::Mutex;
use serde_json::Value;
use tokio::sync::oneshot;
#[derive(Default)]
pub struct EvalResultRegistry {
pending: Mutex<HashMap<String, oneshot::Sender<Value>>>,
}
impl EvalResultRegistry {
pub fn register(&self, id: String) -> oneshot::Receiver<Value> {
let (tx, rx) = oneshot::channel();
if let Ok(mut pending) = self.pending.lock() {
pending.insert(id, tx);
}
rx
}
pub fn complete(&self, id: &str, result: Value) {
if let Ok(mut pending) = self.pending.lock() {
if let Some(tx) = pending.remove(id) {
let _ = tx.send(result);
}
}
}
pub fn cancel(&self, id: &str) {
if let Ok(mut pending) = self.pending.lock() {
pending.remove(id);
}
}
}