fn stram_klines(&self, _symbol: &str, _interval: &str) {
let rt = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
rt.block_on(async {
let keep_running = AtomicBool::new(true);
let kline = kline_stream("btcusdt", "1m");
let mut websocket: WebSockets<'_, WebsocketEvent> = WebSockets::new(|event: WebsocketEvent| {
match event {
WebsocketEvent::Kline(kline_event) => {
debug!( "Symbol: {}, high: {}, low: {}",
kline_event.kline.symbol, kline_event.kline.low, kline_event.kline.high );
}
_ => (),
}
Ok(())
});
websocket.connect(&kline).await.unwrap();
if let Err(e) = websocket.event_loop(&keep_running).await {
println!("Error: {e}");
println!("waiting");
tokio::time::sleep(Duration::from_secs(20)).await;
};
websocket.disconnect().await.unwrap();
println!("disconnected");
});
}
I want to call websocket.connect after websocket.connect, but websocket.connect is not finished, so I can't call websocket.disconnect.
Please help if anyone knows how to terminate the websocket connection.
I'm always grateful to those who help.