Replies: 1 comment
-
Wanted to follow up with an actual implementation example (and also follow up since it has been over a year since this was initially posted). I'm struggling a bit on trying to figure out how I can send an error when something happens in a task - see the following example: async fn bidi_handler(
&self,
request: Request<Streaming<MyRequest>>
) -> Result<Response<Self::MyResponseStream>, Status> {
let mut request_stream = request.into_inner();
let (tx, mut rx) = mpsc::channel(128);
let handle = tokio::spawn(async move {
while Some(something) = request_stream.next().await {
// Do something based on request stream
let result = process(something);
tx.send(result).await.expect("Could not send to channel");
// Test panic to show issue
panic!("Error in spawned task");
}
})
// I can't `await` here to get the error without spawning another task since it will block the return.
//
// handle.await.unwrap_or(|err| tx.send(Err(
// Status::new(Code::Internal, err.to_string());
// ));
Ok(Response::new(ReceiverStream::new(rx)))
} Not sure if there is a way around this or another pattern that can be used. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! How can I cancel a stream on server side with returning a certain status code? Is that even supported?
Beta Was this translation helpful? Give feedback.
All reactions