Skip to main content

read

Function read 

Source
pub fn read(ctx: &Context, id: &str, input: Value, patience: Patience) -> Latest
Expand description

The latest reading of id asked with input: what this process knows now, returned within patience, with a worker reading the source again behind the caller whenever what is known is not current. See the module for what each case costs.

use majordomus_cli::capability::readings::{read, Patience};
use majordomus_cli::synthetic::SyntheticRepository;
use serde_json::json;

let repo = SyntheticRepository::small().unwrap();
let ctx = repo.context().unwrap();
let reading = read(&ctx, "plan.status", json!({}), Patience::WAIT);
// a reading holds what `execute` answers: it is the same source, asked the same way
assert_eq!(reading.value.ok(), ctx.execute("plan.status", json!({})).ok());
// one source per input: asked again it is remembered, not read a second time
read(&ctx, "plan.status", json!({}), Patience::PAGE);
assert_eq!(ctx.executor.readings_remembered(), 1);