我有一个 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.