use crate::boundary::consumer::ConsumerCtx;
use serde_json::Value;
use std::sync::Arc;
pub struct Intake {
ctx: Arc<ConsumerCtx>,
}
impl Intake {
pub fn new(ctx: Arc<ConsumerCtx>) -> Self {
Self { ctx }
}
}
impl super::server::Answerer for Intake {
fn answer(
&self,
peer: &crate::registry::Peer,
request: Value,
) -> Box<dyn Iterator<Item = Value>> {
self.ctx.seen(peer);
match self.ctx.follow(peer, &request) {
Some(frames) => frames,
None => Box::new(std::iter::once(self.ctx.answer_as(peer, &request))),
}
}
}
#[cfg(test)]
mod tests;