Skip to main content

FanInTracker

Struct FanInTracker 

Source
pub struct FanInTracker { /* private fields */ }
Expand description

Tracks which upstream paths have completed for a deferred node.

The tracker maintains a set of expected source nodes and records their outputs as they arrive. Once all expected sources have reported, the tracker is ready and outputs can be merged.

§Example

use adk_graph::deferred::{FanInTracker, MergeStrategy};
use serde_json::json;

let mut tracker = FanInTracker::new(vec!["node_a", "node_b"]);

assert!(!tracker.is_ready());
assert_eq!(tracker.received_count(), 0);
assert_eq!(tracker.expected_count(), 2);

tracker.record("node_a", json!("output_a"));
assert!(!tracker.is_ready());

tracker.record("node_b", json!("output_b"));
assert!(tracker.is_ready());

let merged = tracker.merge(&MergeStrategy::Collect);
assert_eq!(merged, json!(["output_a", "output_b"]));

Implementations§

Source§

impl FanInTracker

Source

pub fn new(expected_sources: Vec<&str>) -> Self

Create a new tracker expecting outputs from the given source nodes.

§Arguments
  • expected_sources - Names of upstream nodes that must complete before this deferred node can execute.
§Example
use adk_graph::deferred::FanInTracker;

let tracker = FanInTracker::new(vec!["branch_1", "branch_2", "branch_3"]);
assert_eq!(tracker.expected_count(), 3);
assert!(!tracker.is_ready());
Source

pub fn is_ready(&self) -> bool

Returns true when all expected sources have reported their output.

§Example
use adk_graph::deferred::FanInTracker;
use serde_json::json;

let mut tracker = FanInTracker::new(vec!["a"]);
assert!(!tracker.is_ready());

tracker.record("a", json!(42));
assert!(tracker.is_ready());
Source

pub fn record(&mut self, source_node: &str, output: Value)

Record the output from a source node.

If the source has already been recorded, the previous value is overwritten (last-write-wins). Recording a source that is not in the expected set is a no-op for readiness but the value is still stored.

§Arguments
  • source_node - The name of the upstream node that produced the output.
  • output - The output value from the source node.
§Example
use adk_graph::deferred::FanInTracker;
use serde_json::json;

let mut tracker = FanInTracker::new(vec!["worker_1", "worker_2"]);
tracker.record("worker_1", json!({"status": "done"}));
assert_eq!(tracker.received_count(), 1);
Source

pub fn merge(&self, strategy: &MergeStrategy) -> Value

Merge all received outputs according to the given strategy.

The merge operation combines all recorded outputs into a single Value based on the MergeStrategy:

§Arguments
  • strategy - The merge strategy to apply.
§Example
use adk_graph::deferred::{FanInTracker, MergeStrategy};
use serde_json::json;

let mut tracker = FanInTracker::new(vec!["a", "b"]);
tracker.record("a", json!({"x": 1}));
tracker.record("b", json!({"y": 2}));

// Collect strategy
let result = tracker.merge(&MergeStrategy::Collect);
assert_eq!(result, json!([{"x": 1}, {"y": 2}]));

// MergeMap strategy
let result = tracker.merge(&MergeStrategy::MergeMap);
assert_eq!(result, json!({"x": 1, "y": 2}));
Source

pub fn received_count(&self) -> usize

Returns the number of outputs received so far.

Source

pub fn expected_count(&self) -> usize

Returns the number of expected source nodes.

Source

pub fn pending_sources(&self) -> Vec<&str>

Returns the names of sources that have not yet reported.

Source

pub fn completed_sources(&self) -> Vec<&str>

Returns the names of sources that have reported.

Trait Implementations§

Source§

impl Debug for FanInTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more