Skip to content

Commit db22c35

Browse files
Fix ListFeaturesStream return type on RouteGuide Tutorial (#586)
1 parent 830b305 commit db22c35

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

examples/routeguide-tutorial.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ prost = "0.7"
185185
futures-core = "0.3"
186186
futures-util = "0.3"
187187
tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "sync", "time"] }
188+
tokio-stream = "0.1"
188189

189190
async-stream = "0.2"
190191
serde = { version = "1.0", features = ["derive"] }
@@ -273,6 +274,7 @@ use std::pin::Pin;
273274
use std::sync::Arc;
274275
use tokio::sync::mpsc;
275276
use tonic::{Request, Response, Status};
277+
use tokio_stream::wrappers::ReceiverStream;
276278
```
277279

278280
```rust
@@ -282,7 +284,7 @@ impl RouteGuide for RouteGuideService {
282284
unimplemented!()
283285
}
284286

285-
type ListFeaturesStream = mpsc::Receiver<Result<Feature, Status>>;
287+
type ListFeaturesStream = ReceiverStream<Result<Feature, Status>>;
286288

287289
async fn list_features(
288290
&self,
@@ -402,7 +404,7 @@ Now let's look at one of our streaming RPCs. `list_features` is a server-side st
402404
need to send back multiple `Feature`s to our client.
403405

404406
```rust
405-
type ListFeaturesStream = mpsc::Receiver<Result<Feature, Status>>;
407+
type ListFeaturesStream = ReceiverStream<Result<Feature, Status>>;
406408

407409
async fn list_features(
408410
&self,
@@ -419,7 +421,7 @@ async fn list_features(
419421
}
420422
});
421423

422-
Ok(Response::new(rx))
424+
Ok(Response::new(ReceiverStream::new(rx)))
423425
}
424426
```
425427

examples/src/routeguide/server.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::time::Instant;
55

66
use futures::{Stream, StreamExt};
77
use tokio::sync::mpsc;
8+
use tokio_stream::wrappers::ReceiverStream;
89
use tonic::transport::Server;
910
use tonic::{Request, Response, Status};
1011

@@ -36,8 +37,7 @@ impl RouteGuide for RouteGuideService {
3637
Ok(Response::new(Feature::default()))
3738
}
3839

39-
type ListFeaturesStream =
40-
Pin<Box<dyn Stream<Item = Result<Feature, Status>> + Send + Sync + 'static>>;
40+
type ListFeaturesStream = ReceiverStream<Result<Feature, Status>>;
4141

4242
async fn list_features(
4343
&self,
@@ -59,9 +59,7 @@ impl RouteGuide for RouteGuideService {
5959
println!(" /// done sending");
6060
});
6161

62-
Ok(Response::new(Box::pin(
63-
tokio_stream::wrappers::ReceiverStream::new(rx),
64-
)))
62+
Ok(Response::new(ReceiverStream::new(rx)))
6563
}
6664

6765
async fn record_route(

0 commit comments

Comments
 (0)