pub struct MemoryStore { /* private fields */ }Expand description
In-memory store used for examples and tests.
Implementations§
Source§impl MemoryStore
impl MemoryStore
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/durable_dag.rs (line 34)
32async fn main() {
33 let dag = DagRunner::new();
34 let db: Arc<dyn duraflow_rs::Storage + Send + Sync> = Arc::new(MemoryStore::new());
35 let ctx = Arc::new(Context {
36 db,
37 completed_count: Arc::new(AtomicUsize::new(0)),
38 });
39
40 let d_dag = DurableDag::new(&dag, ctx.clone()).with_progress(|id, completed| {
41 println!("progress: task={} completed_count={}", id, completed);
42 });
43
44 // Build DAG (same as before)
45 let val1 = d_dag.add("v1", LoadValue(10));
46 let val2 = d_dag.add("v2", LoadValue(20));
47 let val3 = d_dag.add("v3", LoadValue(2));
48
49 let sum_builder = d_dag.add("sum_1_2", Add);
50 let one = d_dag.add("v4", LoadValue(1));
51 let product = d_dag
52 .add("final_prod", Multiply)
53 .depends_on((&sum_builder, &val3, &one));
54 let _sum = sum_builder.depends_on((&val1, &val2));
55
56 dag.run(|fut| {
57 tokio::spawn(fut);
58 })
59 .await
60 .unwrap();
61
62 println!(
63 "Completed tasks: {}",
64 ctx.completed_count
65 .load(std::sync::atomic::Ordering::SeqCst)
66 );
67 println!("Final Result: {}", dag.get(product).unwrap());
68
69 // Resumption
70 println!("\nRestarting DAG...");
71 let dag2 = DagRunner::new();
72 let d_dag2 = DurableDag::new(&dag2, ctx.clone()).with_progress(|id, completed| {
73 println!(
74 "(resumed) progress: task={} completed_count={}",
75 id, completed
76 );
77 });
78
79 let v1 = d_dag2.add("v1", LoadValue(10));
80 let v2 = d_dag2.add("v2", LoadValue(20));
81 let s = d_dag2.add("sum_1_2", Add).depends_on((&v1, &v2));
82
83 dag2.run(|fut| {
84 tokio::spawn(fut);
85 })
86 .await
87 .unwrap();
88 println!("Retrieved cached sum: {}", dag2.get(s).unwrap());
89}Trait Implementations§
Source§impl Default for MemoryStore
impl Default for MemoryStore
Auto Trait Implementations§
impl !Freeze for MemoryStore
impl !RefUnwindSafe for MemoryStore
impl Send for MemoryStore
impl Sync for MemoryStore
impl Unpin for MemoryStore
impl UnsafeUnpin for MemoryStore
impl UnwindSafe for MemoryStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more