| 2 | |
| 3 | #[tokio::main] |
| 4 | async fn main() { |
| 5 | |
| 6 | // path can be '.' in storage::open |
| 7 | let path = "."; |
| 8 | |
| 9 | let storage_name = "blackbird"; |
| 10 | let total_page_size = 1000; |
| 11 | |
| 12 | // ** RamCopies ** |
| 13 | // Dont log to disk and after shutdown , loss data |
| 14 | |
| 15 | let stype = StorageType::RamCopies ; |
| 16 | |
| 17 | // ** DiskCopies ** |
| 18 | // whole storage operation is in-memory but log to disk, |
| 19 | // automatic load whole data after restart, avoid any loss data |
| 20 | // |
| 21 | // let stype = StorageType::DiskCopies; |
| 22 | |
| 23 | |
| 24 | let ops = Options::new(path, storage_name, total_page_size, StorageType::RamCopies, true); |
| 25 | |
| 26 | |
| 27 | let s = Storage::<Pid, User>::open(ops).await.unwrap(); |
| 28 | |
| 29 | |
| 30 | // ---------------------------------------------------------------- |
| 31 | |
| 32 | // create channel |
| 33 | let (sx, mut rx) = mpsc::channel::<Event<Pid, User>>(100); |
| 34 | |
| 35 | // spawn a task for receive event from reporter |
| 36 | tokio::spawn(async move { |
| 37 | |
| 38 | // await on recv |
| 39 | let event = rx.recv().await.unwrap(); |
| 40 | |
| 41 | // handle event |
| 42 | match event { |
| 43 | Event::Query(RQuery::Insert(_key, _doc)) => { |
| 44 | unimplemented!() |
| 45 | } |
| 46 | Event::Query(RQuery::Remove(_key)) => { |
| 47 | unimplemented!() |
| 48 | } |
| 49 | Event::Subscribed(_key) => { |
| 50 | unimplemented!() |
| 51 | } |
| 52 | } |
| 53 | }); |
| 54 | |
| 55 | // subscribe to storage for recieve event from reporter |
| 56 | let _ = s.subscribe(sx).await; |
| 57 | |
| 58 | } |
| 59 | |
| 60 | |
| 61 | type Pid = String; |