-
I've created a streaming response using a channel. I write to the channel in a spawned task, and the streaming response reads from it. let (mut tx,rx) = futures::channel::mpsc::channel::<Result<Bytes,Error>>(1);
let handle = actix_web::rt::spawn( async move {
// long-running writes to the channel
}
});
HttpResponse::Ok()
.streaming(rx) How can I abort the task if the user cancels the request? I don't want to keep processing data if no-one is listening anymore. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
have you found the answer? |
Beta Was this translation helpful? Give feedback.
-
In the original code sample, if the client disconnects then sending chunks to the channel will fail since the receiver side has been dropped. That's how you "detect" this case. The same is true for what I'd recommend, which is the |
Beta Was this translation helpful? Give feedback.
In the original code sample, if the client disconnects then sending chunks to the channel will fail since the receiver side has been dropped. That's how you "detect" this case.
The same is true for what I'd recommend, which is the
channel
orwriter
helpers fromactix_web_lab
.