我有一个actix端点,我需要执行一个同步的http客户端访存来获取一些结果,并返回一些数据。我的端点不能使用async
,所以我不能使用任何.await
方法。
我尝试在端点中使用reqwests阻止客户端,如下所示:
{ ...
let res = reqwest::blocking::get(&fetch_url)?
.json::<MyResp>()?;
...
但这给了我错误:
thread 'main' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.', /.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.9/src/runtime/enter.rs:19:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
最佳答案
我不知道如何使它与reqwest
一起使用(它必须与actix有一些怪异的冲突),但是由于某种原因,它与chttp
可以很好地工作。chttp::get(&fetch_url)?.text()?;
关于rust - 在actix线程中进行同步http客户端访存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60580769/