mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 21:21:32 +00:00
krata: reorganize crates
This commit is contained in:
35
crates/xen/xenstore/examples/list.rs
Normal file
35
crates/xen/xenstore/examples/list.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use std::env::args;
|
||||
|
||||
use xenstore::client::{XsdClient, XsdInterface};
|
||||
use xenstore::error::Result;
|
||||
|
||||
async fn list_recursive(client: &XsdClient, path: &str) -> Result<()> {
|
||||
let mut pending = vec![path.to_string()];
|
||||
|
||||
while let Some(ref path) = pending.pop() {
|
||||
let children = client.list(path).await?;
|
||||
for child in children {
|
||||
let full = format!("{}/{}", if path == "/" { "" } else { path }, child);
|
||||
let value = client
|
||||
.read_string(full.as_str())
|
||||
.await?
|
||||
.expect("expected value");
|
||||
println!("{} = {:?}", full, value,);
|
||||
pending.push(full);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
|
||||
let client = XsdClient::open().await?;
|
||||
loop {
|
||||
list_recursive(&client, "/").await?;
|
||||
if args().nth(1).unwrap_or("none".to_string()) != "stress" {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
23
crates/xen/xenstore/examples/watch.rs
Normal file
23
crates/xen/xenstore/examples/watch.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use std::env::args;
|
||||
use xenstore::client::XsdClient;
|
||||
use xenstore::error::Result;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
|
||||
let path = args().nth(1).unwrap_or("/local/domain".to_string());
|
||||
let client = XsdClient::open().await?;
|
||||
let mut handle = client.watch(&path).await?;
|
||||
let mut count = 0;
|
||||
loop {
|
||||
let Some(event) = handle.receiver.recv().await else {
|
||||
break;
|
||||
};
|
||||
println!("{}", event);
|
||||
count += 1;
|
||||
if count >= 3 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user