1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Finding the deferred tool output a client asks for
//! (`rho/session/tool_output`) in a feed: its buffered live events first,
//! which hold what only live events show, such as a `diff`'s whole files,
//! newest first, by the refs each kept when pushed, or worked out by the
//! first search for one pushed while no client deferred, then its saved
//! transcript, which the lock is not held for.
use super::Feed;
use crate::app::session_events::{Deferrables, NewestTurns, Wanted};
impl Feed {
/// Takes the wanted items the buffered events carry, and the
/// transcript's turns to search after; `None` when the session defers
/// nothing, as one an agent runtime runs, which holds no item a client
/// could ask for.
pub(in crate::app::daemon_host::sessions) fn find_tool_output(
&self,
wanted: &mut Wanted,
) -> Option<NewestTurns> {
let mut state = self.state();
if !state.defers() {
return None;
}
for buffered in state.buffer.iter_mut().rev() {
if wanted.complete() {
break;
}
// Pushed while no client deferred: worked out once, now.
let deferrables = buffered
.deferrables
.get_or_insert_with(|| Deferrables::of(&buffered.event.event));
wanted.find_listed(&buffered.event.event, deferrables);
}
Some(state.transcript.newest_turns())
}
}
#[cfg(test)]
#[path = "feed_tool_output_tests.rs"]
mod tests;