use std::{future::Future, pin::Pin, sync::OnceLock}; use incria::{ deps, thunk::{Thunk, ThunkMapper}, Mapper, }; type Key = (usize, usize); type Value = usize; #[derive(Debug, Default)] struct CellThunk; impl Thunk for CellThunk { fn compute(&self, key: Key) -> Pin + Send + '_>> { Box::pin(async move { if key.0 > 0 { let prev1 = *cell_mapping().get(&(key.0 - 1, key.1 - 1)).await; let prev2 = *cell_mapping().get(&(key.0 - 1, key.1)).await; let prev3 = *cell_mapping().get(&(key.0 - 1, key.1 + 1)).await; prev1 + prev2 + prev3 } else { 1 } }) } } type CellMapping = ThunkMapper; static CELL_MAPPING: OnceLock = OnceLock::new(); fn cell_mapping() -> &'static CellMapping { CELL_MAPPING.get_or_init(CellMapping::default) } const N: usize = 5; #[tokio::main] async fn main() { deps::with_node_id(deps::next_node_id(), async { let val = *dbg!(cell_mapping().get(&(N, N)).await); // println!("{}", dep_graphviz()); deps::mark_dirty(21); // println!("{}", dep_graphviz()); assert_eq!(val, *cell_mapping().get(&(N, N)).await); println!("{}", deps::dep_graphviz()); }) .await; }