From d080463c3c86ac4729f5e0d99332b8f556811755 Mon Sep 17 00:00:00 2001 From: Thomas Karpiniec Date: Fri, 28 Jun 2024 11:16:09 +1000 Subject: [PATCH] Make example program test dropping the WatchHandle --- examples/watch.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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)); } -- 2.39.5