Implement the authenticated structured entry viewer

This commit is contained in:
Hermes Agent
2026-08-10 06:45:39 +00:00
parent 57a79b7d21
commit cf7a6216ac
8 changed files with 758 additions and 28 deletions

View File

@@ -1,7 +1,10 @@
//! Small in-process executor for storage calls. It never launches a process.
use std::{
sync::mpsc::{self, Receiver, Sender},
sync::{
Mutex,
mpsc::{self, Receiver, Sender},
},
thread,
time::Duration,
};
@@ -17,6 +20,7 @@ use crate::app::{AsyncPayload, AsyncResult, RequestToken};
pub struct AsyncExecutor {
sender: Sender<AsyncResult>,
receiver: Receiver<AsyncResult>,
tasks: Mutex<Vec<thread::JoinHandle<()>>>,
}
#[derive(Debug, Eq, PartialEq)]
@@ -147,7 +151,11 @@ impl Default for AsyncExecutor {
impl AsyncExecutor {
pub fn new() -> Self {
let (sender, receiver) = mpsc::channel();
Self { sender, receiver }
Self {
sender,
receiver,
tasks: Mutex::new(Vec::new()),
}
}
pub fn submit<F>(&self, token: RequestToken, work: F)
@@ -155,12 +163,16 @@ impl AsyncExecutor {
F: FnOnce() -> Result<AsyncPayload, String> + Send + 'static,
{
let sender = self.sender.clone();
thread::spawn(move || {
let task = thread::spawn(move || {
let _ignored = sender.send(AsyncResult {
token,
payload: work(),
});
});
self.tasks
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.push(task);
}
pub fn drain(&self) -> impl Iterator<Item = AsyncResult> + '_ {
@@ -168,6 +180,18 @@ impl AsyncExecutor {
}
}
impl Drop for AsyncExecutor {
fn drop(&mut self) {
let tasks = self
.tasks
.get_mut()
.unwrap_or_else(std::sync::PoisonError::into_inner);
for task in tasks.drain(..) {
let _ignored = task.join();
}
}
}
#[cfg(test)]
mod tests {
use std::time::Duration;