-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use tokio runtime for examples. Use futures::Future as future impleme…
…ntation for clients
- Loading branch information
Showing
7 changed files
with
93 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 19 additions & 8 deletions
27
examples/minimal_client_service/src/minimal_client_async.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
use anyhow::{Error, Result}; | ||
use futures::join; | ||
use futures::Future; | ||
use rclrs::Node; | ||
use std::env; | ||
use std::thread; | ||
use tokio; | ||
|
||
fn main() -> Result<(), Error> { | ||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
let context = rclrs::Context::new(env::args()).unwrap(); | ||
|
||
let mut node = context.create_node("minimal_client")?; | ||
|
||
let client = node.create_client::<example_interfaces::srv::AddTwoInts>("add_two_ints")?; | ||
|
||
let request = example_interfaces::srv::AddTwoInts_Request { a: 41, b: 1 }; | ||
|
||
println!("Starting client"); | ||
|
||
std::thread::sleep(std::time::Duration::from_millis(500)); | ||
|
||
let future = client.call_async(&request)?; | ||
let request = example_interfaces::srv::AddTwoInts_Request { a: 41, b: 1 }; | ||
|
||
let future = client.call_async(&request); | ||
|
||
println!("Waiting for response"); | ||
let response = rclrs::spin_until_future_complete(&node, future)?; | ||
|
||
let spin_thread = std::thread::spawn(move || { | ||
rclrs::spin(&node); | ||
}); | ||
|
||
let response = future.await; | ||
println!( | ||
"Result of {} + {} is: {}", | ||
request.a, request.b, response.sum | ||
); | ||
"Result of {} + {} is: {}", | ||
request.a, request.b, response.unwrap().sum | ||
); | ||
spin_thread.join(); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters