use super::super::{Call, Capture};
use super::{Mailbox, Slots, lock_mail};
pub(super) type Key = (String, String, String);
fn key(call: &Call) -> Key {
(
call.client.clone(),
call.tool.clone(),
call.input.to_string(),
)
}
impl Slots {
fn busy(&self, now: i64, client: &str) -> bool {
self.live
.values()
.any(|slot| slot.client == client && slot.works(now))
}
}
impl Mailbox {
pub fn busy(&self, now: i64, client: &str) -> bool {
lock_mail(&self.cell).busy(now, client)
}
pub fn remember(&self, now: i64, call: &Call, capture: &Capture) {
lock_mail(&self.cell)
.known
.insert(key(call), (now, capture.clone()));
}
pub fn known(&self, now: i64, call: &Call) -> Option<Capture> {
let slots = lock_mail(&self.cell);
slots
.known
.get(&key(call))
.filter(|_| slots.busy(now, &call.client))
.map(|(_, capture)| capture.clone())
}
}