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"
|
||||
dbus-tokio = "0.7.5"
|
||||
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::sync::Arc;
|
||||
|
||||
use futures_util::stream::StreamExt;
|
||||
use tokio::{
|
||||
task::JoinHandle,
|
||||
time::Duration,
|
||||
|
@ -26,6 +27,7 @@ use tokio::{
|
|||
|
||||
use mmdbus::{
|
||||
dbus::{
|
||||
message::MatchRule,
|
||||
nonblock::{
|
||||
SyncConnection, Proxy,
|
||||
stdintf::org_freedesktop_dbus::ObjectManager,
|
||||
|
@ -176,16 +178,42 @@ impl From<i32> for ModemState {
|
|||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), DBusError> {
|
||||
let modems = ModemManager::connect()?.modems().await?;
|
||||
async fn print_foo(mm: ModemManager) -> Result<(), DBusError> {
|
||||
let modems = mm.modems().await?;
|
||||
println!("Modems: {:?}", modems);
|
||||
|
||||
for modem in modems {
|
||||
println!("Modem: {:?}", modem);
|
||||
println!("Enabled: {:?}", modem.enabled().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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue