Skip to content

Detect client drops in bidirectional streams #781

@katetsu

Description

@katetsu

Hi,

Im following the routeguide tutorial and am wondering if there is a way for detecting when a client drops when working with bidirectional streams.

Here is the code snippet:

in the bidirectional stream, how can know if a client was not able to receive the response?

    async fn route_chat(
        &self,
        request: Request<tonic::Streaming<RouteNote>>,
    ) -> Result<Response<Self::RouteChatStream>, Status> {
        println!("RouteChat");

        let mut notes = HashMap::new();
        let mut stream = request.into_inner();

        let output = async_stream::try_stream! {
            while let Some(note) = stream.next().await {
                let note = note?;

                let location = note.location.clone().unwrap();

                let location_notes = notes.entry(location).or_insert(vec![]);
                location_notes.push(note);

                for note in location_notes {
                    yield note.clone();
                }
            }
        };

        Ok(Response::new(Box::pin(output)))
    }

Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-examplesE-easyCall for participation: Experience needed to fix: Easy / not much

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions