Use tokio::spawn in routeguide
This commit is contained in:
@@ -52,19 +52,17 @@ impl server::RouteGuide for RouteGuide {
|
|||||||
&self,
|
&self,
|
||||||
request: Request<Rectangle>,
|
request: Request<Rectangle>,
|
||||||
) -> Result<Response<Self::ListFeaturesStream>, Status> {
|
) -> Result<Response<Self::ListFeaturesStream>, Status> {
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
println!("ListFeatures = {:?}", request);
|
println!("ListFeatures = {:?}", request);
|
||||||
|
|
||||||
let (mut tx, rx) = mpsc::channel(4);
|
let (mut tx, rx) = mpsc::channel(4);
|
||||||
|
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
|
|
||||||
thread::spawn(move || {
|
tokio::spawn(async move {
|
||||||
for feature in &state.features[..] {
|
for feature in &state.features[..] {
|
||||||
if in_range(feature.location.as_ref().unwrap(), request.get_ref()) {
|
if in_range(feature.location.as_ref().unwrap(), request.get_ref()) {
|
||||||
println!(" => send {:?}", feature);
|
println!(" => send {:?}", feature);
|
||||||
tx.try_send(Ok(feature.clone())).unwrap();
|
tx.send(Ok(feature.clone())).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user