是否可以在没有异步的情况下在 Rust 中使用 .await 函数?

问题描述

我在 rust 中使用 tokio 进行异步处理,在 rust 中我正在调用使用 async.await 进行异步处理的函数,但是我可以包装这些函数吗以某种方式并在没有 async 的函数中调用它们?下面是我想要做的伪代码。


async fn asynchronous_func() -> Vec<u32> {
    let vec = Arc::new(Mutex::new(vec![]));
    // do something await
    let vec = Arc::try_unwrap(vec).unwrap();
    let vec = vec.try_inner().unwrap();
    vec
}


// without async
fn wrapper_func() -> Vec<u32> {
   let res = asynchronous_func().await;
   // do something
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...