Stop server side streaming after client disconnects

Hello!

I’m trying to implement GRPC Health Checking Protocol. I would like the server to stop streaming to the client after the client disconnects. I found possible solution here, but I can’t find a way to receive a :shutdown message. Below is my attempt:

# health_service.ex
defmodule Grpc.HealthService do
  use GRPC.Server, service: Proto.Grpc.Health.V1.HealthService.Service
  ...
  @spec watch(Health.HealthCheckRequest.t(), GRPC.Server.Stream.t()) ::
          GRPC.Server.Stream.t()
  def watch(request, stream) do
    status = get_health_status(request.service)
    GRPC.Server.send_reply(stream, status)

    receive do
      x -> dbg(x)
    end
  end
  ...
end

# test.exs
spawn(fn ->
  {:ok, channel} = GRPC.Stub.connect("localhost:1234")
  request = %Health.HealthCheckRequest{service: ""}
  {:ok, _stream} = Health.HealthService.Stub.watch(channel, request);
end)
Process.sleep(10000)