Skip to content

Commit

Permalink
Fix ListFeaturesStream return type on RouteGuide Tutorial (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura authored Apr 4, 2021
1 parent 830b305 commit db22c35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 5 additions & 3 deletions examples/routeguide-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ prost = "0.7"
futures-core = "0.3"
futures-util = "0.3"
tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "sync", "time"] }
tokio-stream = "0.1"

async-stream = "0.2"
serde = { version = "1.0", features = ["derive"] }
Expand Down Expand Up @@ -273,6 +274,7 @@ use std::pin::Pin;
use std::sync::Arc;
use tokio::sync::mpsc;
use tonic::{Request, Response, Status};
use tokio_stream::wrappers::ReceiverStream;
```

```rust
Expand All @@ -282,7 +284,7 @@ impl RouteGuide for RouteGuideService {
unimplemented!()
}

type ListFeaturesStream = mpsc::Receiver<Result<Feature, Status>>;
type ListFeaturesStream = ReceiverStream<Result<Feature, Status>>;

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

```rust
type ListFeaturesStream = mpsc::Receiver<Result<Feature, Status>>;
type ListFeaturesStream = ReceiverStream<Result<Feature, Status>>;

async fn list_features(
&self,
Expand All @@ -419,7 +421,7 @@ async fn list_features(
}
});

Ok(Response::new(rx))
Ok(Response::new(ReceiverStream::new(rx)))
}
```

Expand Down
8 changes: 3 additions & 5 deletions examples/src/routeguide/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::time::Instant;

use futures::{Stream, StreamExt};
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use tonic::transport::Server;
use tonic::{Request, Response, Status};

Expand Down Expand Up @@ -36,8 +37,7 @@ impl RouteGuide for RouteGuideService {
Ok(Response::new(Feature::default()))
}

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

async fn list_features(
&self,
Expand All @@ -59,9 +59,7 @@ impl RouteGuide for RouteGuideService {
println!(" /// done sending");
});

Ok(Response::new(Box::pin(
tokio_stream::wrappers::ReceiverStream::new(rx),
)))
Ok(Response::new(ReceiverStream::new(rx)))
}

async fn record_route(
Expand Down

0 comments on commit db22c35

Please sign in to comment.