reifydb_sub_flow/worker/
mod.rs1pub mod parallel;
5pub mod processor;
6pub mod same;
7
8pub use parallel::ParallelWorkerPool;
9pub use processor::WorkerPool;
10use reifydb_core::{CommitVersion, interface::FlowId};
11pub use same::SameThreadedWorker;
12
13use crate::flow::FlowChange;
14
15#[derive(Debug, Clone)]
17pub struct UnitOfWork {
18 pub flow_id: FlowId,
20
21 pub version: CommitVersion,
23
24 pub source_changes: Vec<FlowChange>,
27}
28
29impl UnitOfWork {
30 pub fn new(flow_id: FlowId, version: CommitVersion, source_changes: Vec<FlowChange>) -> Self {
32 Self {
33 flow_id,
34 version,
35 source_changes,
36 }
37 }
38}
39
40#[derive(Debug, Clone)]
46pub struct UnitsOfWork(Vec<Vec<UnitOfWork>>);
47
48impl UnitsOfWork {
49 pub fn new(flow_units: Vec<Vec<UnitOfWork>>) -> Self {
51 Self(flow_units)
52 }
53
54 pub fn empty() -> Self {
56 Self(Vec::new())
57 }
58
59 pub fn is_empty(&self) -> bool {
61 self.0.is_empty()
62 }
63
64 pub fn flow_count(&self) -> usize {
66 self.0.len()
67 }
68
69 pub fn total_units(&self) -> usize {
71 self.0.iter().map(|units| units.len()).sum()
72 }
73
74 pub fn as_inner(&self) -> &Vec<Vec<UnitOfWork>> {
76 &self.0
77 }
78
79 pub fn into_inner(self) -> Vec<Vec<UnitOfWork>> {
81 self.0
82 }
83}
84
85impl From<Vec<Vec<UnitOfWork>>> for UnitsOfWork {
86 fn from(flow_units: Vec<Vec<UnitOfWork>>) -> Self {
87 Self(flow_units)
88 }
89}
90
91impl IntoIterator for UnitsOfWork {
92 type Item = Vec<UnitOfWork>;
93 type IntoIter = std::vec::IntoIter<Vec<UnitOfWork>>;
94
95 fn into_iter(self) -> Self::IntoIter {
96 self.0.into_iter()
97 }
98}