Use tokio::spawn in routeguide

This commit is contained in:
Lucio Franco
2019-09-21 11:09:57 -06:00
parent df8e0a0a97
commit 322f346b97
+2 -4
View File
@@ -52,19 +52,17 @@ impl server::RouteGuide for RouteGuide {
&self,
request: Request<Rectangle>,
) -> Result<Response<Self::ListFeaturesStream>, Status> {
use std::thread;
println!("ListFeatures = {:?}", request);
let (mut tx, rx) = mpsc::channel(4);
let state = self.state.clone();
thread::spawn(move || {
tokio::spawn(async move {
for feature in &state.features[..] {
if in_range(feature.location.as_ref().unwrap(), request.get_ref()) {
println!(" => send {:?}", feature);
tx.try_send(Ok(feature.clone())).unwrap();
tx.send(Ok(feature.clone())).await.unwrap();
}
}