wavelet/lib.rs
1use enum_as_inner::EnumAsInner;
2pub use petgraph::prelude::NodeIndex;
3
4#[cfg(feature = "channel")]
5pub mod channel;
6#[cfg(feature = "factories")]
7pub mod factory;
8#[cfg(feature = "runtime")]
9pub mod runtime;
10#[cfg(feature = "testing")]
11pub mod testing;
12#[cfg(feature = "wsnl")]
13pub mod wsnl;
14
15// TODO list:
16// - Improvements to GC so we can remove hanging event driver resources
17// - More standard node library implementations
18// - Timer driver improvements
19// - Trace logging + metrics capable of tracking subgraphs
20
21/// Defines how wsnl relate to each other in the computation graph.
22///
23/// Relationships determine when and how changes propagate between wsnl.
24/// This is fundamental to the incremental computation model - wsnl only
25/// recompute when their dependencies change.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumAsInner)]
27pub enum Relationship {
28 /// The parent node will schedule this node when it mutates.
29 ///
30 /// Use `Trigger` when this node should react to changes
31 /// in the parent node. This creates an active dependency.
32 Trigger,
33
34 /// This node can read from the parent but won't be automatically scheduled.
35 ///
36 /// Use `Observe` when this node needs access to the parent's data but
37 /// doesn't need to react to changes in the parent. The node can check if the
38 /// parent has mutated using `ExecutionContext::has_mutated()`. This is most
39 /// commonly used when a node reacts to a specific trigger relationship to
40 /// one parent but just needs the data of another.
41 Observe,
42}
43
44/// Controls how a node's execution affects the broader computation graph.
45///
46/// Returned by a node's cycle function to indicate what should happen
47/// after the node completes execution.
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumAsInner)]
49pub enum Control {
50 /// Schedule all wsnl with `Trigger` relationships to this node.
51 ///
52 /// Use when this node has mutated and downstream wsnl should react
53 /// to the changes.
54 Broadcast,
55
56 /// This node did not change - don't schedule any dependent wsnl.
57 ///
58 /// Use when the node has processed data but its state didn't
59 /// change in a way that would affect downstream computations.
60 Unchanged,
61
62 /// Signal the entire runtime to terminate gracefully.
63 ///
64 /// Use when a critical condition is met and the entire stream
65 /// processing pipeline should shut down.
66 Terminate,
67
68 /// Mark this node for removal from the graph.
69 ///
70 /// Use when this node has completed its purpose and should be
71 /// cleaned up. The node will be removed after the current cycle.
72 Sweep,
73}
74
75impl From<bool> for Control {
76 fn from(value: bool) -> Self {
77 if value {
78 Control::Broadcast
79 } else {
80 Control::Unchanged
81 }
82 }
83}
84
85pub mod prelude {
86 pub use crate::{Control, Relationship};
87
88 #[cfg(feature = "runtime")]
89 pub use crate::runtime::*;
90
91 #[cfg(feature = "factories")]
92 pub use crate::factory::*;
93}