diff options
author | Romeo Disca <romeo.disca@gmail.com> | 2020-08-18 06:40:46 +0200 |
---|---|---|
committer | Romeo Disca <romeo.disca@gmail.com> | 2020-08-18 06:40:46 +0200 |
commit | a14cc3f38b67e6054bdbff8aff7c60967f342194 (patch) | |
tree | dab55097ece8372c757726a3a81c674710b80894 /examples/ping.rs | |
parent | bfc63947702ffb3ca1dca6e8184f0998fb98ed13 (diff) |
refactor: change crate to lib
Diffstat (limited to 'examples/ping.rs')
-rw-r--r-- | examples/ping.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/ping.rs b/examples/ping.rs new file mode 100644 index 0000000..4a6a7cb --- /dev/null +++ b/examples/ping.rs @@ -0,0 +1,38 @@ + + +use std::error::Error; +use std::time::Duration; +use std::sync::Arc; + +use flicbtn::*; + +#[tokio::main] +async fn main() -> Result<(), Box<dyn Error>> { + + let event = event_handler(|event| { println!("ping response: {:?}", event); }); + let event2 = event_handler(|event| { println!("ping response: {:?}", event); }); + + let client = FlicClient::new("127.0.0.1:5551").await? + .register_event_handler(event).await + .register_event_handler(event2).await + ; + let client1 = Arc::new(client); + let client2 = client1.clone(); + + let cmd = tokio::spawn(async move { + client1.submit(Command::GetInfo).await; + tokio::time::delay_for(Duration::from_secs(3)).await; + client1.submit(Command::GetInfo).await; + tokio::time::delay_for(Duration::from_secs(3)).await; + client1.stop().await; + }); + let lst = tokio::spawn(async move { + client2.listen().await; + println!("stop"); + }); + + lst.await?; + cmd.await?; + + Ok(()) +} |