Hello,
I use a stream to consume HTTP SSE response, example code with websocket (this code fail just now because demo.piesocket.com have a SSL problem) :
use async_std::task;
use futures_util::StreamExt;
use reqwest::{self, Method};
async fn job() {
let response = reqwest::Client::new()
.request(Method::GET, format!("wss://demo.piesocket.com/v3/channel_1?api_key=oCdCMcMPQpbvNjUIzqtvF1d2X2okWpDQj4AwARJuAgtjhzKxVEjQU6IdCjwm¬ify_self"))
.send()
.await.unwrap();
let mut stream = response.bytes_stream();
while let Some(_) = stream.next().await {
println!("Hello world")
}
}
fn main() {
task::block_on(job());
}
In that code, job
is blocking on while let Some(_) = stream.next().await {
. I would like to be able to stop the loop if my application want to stop. I think to use a channel to send message. But, how can I consume the stream, and sometimes, for example if a timeout is reached, take a look into my channel to see if an interrupt request has been sent ?
Thanks in advance !