Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

如何在同步的 Rust 方法中调用异步代码 - Tokio 使用中的几点教训 #98

giscus[bot] Bot announced in Articles
Discussion options

如何在同步的 Rust 方法中调用异步代码 - Tokio 使用中的几点教训

在同步的 Rust 方法中调用异步代码经常会导致一些问题,特别是对于不熟悉异步 Rust runtime 底层原理的初学者。在本文中,我们将讨论我们遇到的一个特殊问题,并分享我们采取的解决方法的经验。

最近在做我们的 GreptimeDB 项目的时候遇到一个关于在同步 Rust 方法中调用异步代码的问题。经过一系列故障排查后,我们弄清了问题的原委,这大大加深了对异步 Rust 的理解,因此在这篇

https://rustmagazine.org/issue-3/bridging-async-and-sync-in-rust-zh/

You must be logged in to vote

Replies: 1 comment

Comment options

 futures::executor::block_on(
 RUNTIME.spawn(async move {
 let mut res = vec![];
 for i in 0..bound {
 res.push(i);
 tokio::time::sleep(Duration::from_millis(100)).await;
 }
 res
 })
).unwrap();

例子这样看上去更干净些

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /