rust-tokio

How to remotely shut down running tasks with Tokio

 ̄綄美尐妖づ 提交于 2021-01-03 08:28:51
问题 I have a UDP socket that is receiving data pub async fn start() -> Result<(), std::io::Error> { loop { let mut data = vec![0; 1024]; socket.recv_from(&mut data).await?; } } This code is currently blocked on the .await when there is no data coming in. I want to gracefully shut down my server from my main thread, so how do I send a signal to this .await that it should stop sleeping and shut down instead? 回答1: Note: This answer currently links to the 1.x version of Tokio, but applies to Tokio 0

panic with "thread 'main' panicked at 'not currently running on the Tokio runtime

≡放荡痞女 提交于 2020-12-29 09:22:47
问题 I'm using the example code on elastic search's blog post about their new crate and I'm unable to get it working as intended. The thread panics with thread 'main' panicked at 'not currently running on the Tokio runtime.' . What is the Tokio runtime, how do I configure it and why must I? use futures::executor::block_on; async elastic_search_example() -> Result<(), Box<dyn Error>> { let index_response = client .index(IndexParts::IndexId("tweets", "1")) .body(json!({ "user": "kimchy", "post_date"

panic with "thread 'main' panicked at 'not currently running on the Tokio runtime

旧巷老猫 提交于 2020-12-29 09:21:41
问题 I'm using the example code on elastic search's blog post about their new crate and I'm unable to get it working as intended. The thread panics with thread 'main' panicked at 'not currently running on the Tokio runtime.' . What is the Tokio runtime, how do I configure it and why must I? use futures::executor::block_on; async elastic_search_example() -> Result<(), Box<dyn Error>> { let index_response = client .index(IndexParts::IndexId("tweets", "1")) .body(json!({ "user": "kimchy", "post_date"

Do I need to move away from Tokio as I cannot split streams in TLS connections?

↘锁芯ラ 提交于 2020-11-29 11:11:03
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but

Do I need to move away from Tokio as I cannot split streams in TLS connections?

本小妞迷上赌 提交于 2020-11-29 11:10:58
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but

Do I need to move away from Tokio as I cannot split streams in TLS connections?

为君一笑 提交于 2020-11-29 11:10:39
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but