MCPcopy Create free account
hub / github.com/Rustixir/darkbird / main

Function main

example/complex.rs:5–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3
4#[tokio::main]
5async fn main() {
6
7 // path can be '.' in storage::open
8 let path = ".";
9
10 let storage_name = "blackbird";
11 let total_page_size = 1000;
12
13 // ** RamCopies **
14 // Dont log to disk and after shutdown , loss data
15
16 let stype = StorageType::RamCopies ;
17
18 // ** DiskCopies **
19 // whole storage operation is in-memory but log to disk,
20 // automatic load whole data after restart, avoid any loss data
21 //
22 // let stype = StorageType::DiskCopies;
23
24
25 let ops = Options::new(path, storage_name, total_page_size, StorageType::RamCopies, true);
26
27
28 // ***************************************************************************
29 // ** **
30 // ** 1. Storage is built for high concurrency usage **
31 // ** 2. dont need to Mutex / Rwlock **
32 // ** 3. it is safe for shared between thread **
33 // ** **
34 // ***************************************************************************
35
36
37
38 // create storage and initialize other service (reporter, disk_log)
39 //
40 // when calling storage::open, it load whole storage from disk
41 //
42 let s = Arc::new(Storage::<Pid, User>::open(ops).await.unwrap());
43
44
45
46 // spawn a task for inserting to storage
47 let s1 = s.clone();
48 tokio::spawn(async move {
49 let _ = s1.insert("98 000xxxxx1".to_owned(), User::new("DanyalMh")).await;
50 });
51
52
53
54 // spawn another task for inserting to storage
55 let s2 = s.clone();
56 tokio::spawn(async move {
57 let _ = s2.insert("98 000xxxxx1".to_owned(), User::new("DanyalMh")).await;
58 });
59
60
61
62 let s3 = s.clone();

Callers

nothing calls this directly

Calls 2

insertMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected