Try running queries and monitor at the same time
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
3e8951dd24
commit
58d096ef13
2 changed files with 34 additions and 4 deletions
|
@ -11,3 +11,5 @@ async-trait = "0.1.56"
|
||||||
mmdbus = "1.18.6"
|
mmdbus = "1.18.6"
|
||||||
dbus-tokio = "0.7.5"
|
dbus-tokio = "0.7.5"
|
||||||
tokio = { version = "1.19.2", features = [ "time", "macros", "rt-multi-thread" ] }
|
tokio = { version = "1.19.2", features = [ "time", "macros", "rt-multi-thread" ] }
|
||||||
|
futures = "0.3"
|
||||||
|
futures-util = "0.3"
|
||||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -19,6 +19,7 @@ use mm::modem::Modem as ModemAccess;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use futures_util::stream::StreamExt;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
task::JoinHandle,
|
task::JoinHandle,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
|
@ -26,6 +27,7 @@ use tokio::{
|
||||||
|
|
||||||
use mmdbus::{
|
use mmdbus::{
|
||||||
dbus::{
|
dbus::{
|
||||||
|
message::MatchRule,
|
||||||
nonblock::{
|
nonblock::{
|
||||||
SyncConnection, Proxy,
|
SyncConnection, Proxy,
|
||||||
stdintf::org_freedesktop_dbus::ObjectManager,
|
stdintf::org_freedesktop_dbus::ObjectManager,
|
||||||
|
@ -176,16 +178,42 @@ impl From<i32> for ModemState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
async fn print_foo(mm: ModemManager) -> Result<(), DBusError> {
|
||||||
async fn main() -> Result<(), DBusError> {
|
let modems = mm.modems().await?;
|
||||||
let modems = ModemManager::connect()?.modems().await?;
|
|
||||||
println!("Modems: {:?}", modems);
|
println!("Modems: {:?}", modems);
|
||||||
|
|
||||||
for modem in modems {
|
for modem in modems {
|
||||||
println!("Modem: {:?}", modem);
|
println!("Modem: {:?}", modem);
|
||||||
println!("Enabled: {:?}", modem.enabled().await);
|
println!("Enabled: {:?}", modem.enabled().await);
|
||||||
println!("Model: {:?}", modem.model().await);
|
println!("Model: {:?}", modem.model().await);
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let dbus = DBus::connect()?;
|
||||||
|
|
||||||
|
let mut interval = tokio::time::interval(Duration::from_secs(2));
|
||||||
|
|
||||||
|
let calls = async {
|
||||||
|
loop {
|
||||||
|
let mm = ModemManager { dbus: dbus.clone() };
|
||||||
|
interval.tick().await;
|
||||||
|
let _ = print_foo(mm).await;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mr = MatchRule::new_signal("org.freedesktop.DBus.Properties", "PropertiesChanged");
|
||||||
|
|
||||||
|
let (_in_signal, stream) = dbus.conn.add_match(mr).await?.stream();
|
||||||
|
let stream = stream.for_each(|(foo, (source,)): (_, (String,))| {
|
||||||
|
println!("Foo {}; {:?}", source, foo);
|
||||||
|
async {}
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.await;
|
||||||
|
|
||||||
|
futures::join!(stream, calls);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue