From: Thomas Karpiniec Date: Fri, 28 Jun 2024 01:16:09 +0000 (+1000) Subject: Make example program test dropping the WatchHandle X-Git-Tag: v0.1.0~3 X-Git-Url: https://code.octet-stream.net/netwatcher/commitdiff_plain/d080463c3c86ac4729f5e0d99332b8f556811755?ds=inline;hp=8f78cf14e9d177b9dfd43b6b35038d391821627e Make example program test dropping the WatchHandle --- diff --git a/examples/watch.rs b/examples/watch.rs index 4129dc6..2f9539c 100644 --- a/examples/watch.rs +++ b/examples/watch.rs @@ -1,13 +1,18 @@ use std::time::Duration; fn main() { - let _handle = netwatcher::watch_interfaces(|update| { + println!("Watching for changes for 30 seconds..."); + + let handle = netwatcher::watch_interfaces(|update| { println!("Interface update!"); println!("State: {:?}", update.interfaces); println!("Diff: {:?}", update.diff); }); - loop { - std::thread::sleep(Duration::from_secs(60)); - } + std::thread::sleep(Duration::from_secs(30)); + + drop(handle); + println!("Stopped watching! Program will end in 30 seconds."); + + std::thread::sleep(Duration::from_secs(30)); }