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,
client: &crate::registry::Client,
request: Value,
) -> Box<dyn Iterator<Item = Value>> {
match self.ctx.follow(client, &request) {
Some(frames) => frames,
None => Box::new(std::iter::once(self.ctx.answer_as(client, &request))),
}
}
}
#[cfg(test)]
mod tests;