sai*_*ing 4 rust rust-tokio rust-axum
我知道 Axum 是建立在 Tokio 之上的,并且 Tokio 有一个多线程调度程序和当前线程调度程序。
是否可以设置运行时以使其在单线程中服务请求?
由于 axum 是在 tokio 运行时中使用#[tokio::main]宏或您设置的系统生成的。未来的处理方式是您配置运行时的方式。
如果您使用宏,只需执行以下操作:
#[tokio::main(flavor = "current_thread")]
async fn main() {
// Axum code here...
}
Run Code Online (Sandbox Code Playgroud)
以下是有关宏的更多信息的文档:https://docs.rs/tokio/0.3.3/tokio/attr.main.html#current-thread-runtime
这是设置 tokio 运行时的非糖化方法:https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.new_current_thread
| 归档时间: |
|
| 查看次数: |
2220 次 |
| 最近记录: |