Skip to content

Commit

Permalink
async: Add async await
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Mar 14, 2024
1 parent 3eb7b4b commit 593f870
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,17 @@
- [异步 async](async/index.md)
- [理解 Futures 与 Tasks](async/futures-and-tasks.md)
- [理解 async/await](async/async-await.md)
- [内存保持 Pinning](async/mem-pinning.md)
- [生命周期与内存保持 Lifetimes and Pinning](async/lifetimes-pinning.md)
- [流 Streams](async/streams.md)
- [一次执行多个 Futures](async/multi-futures.md)
- [标准库中的 future 模块](async/future-module.md)
- [mio 库](async/mio.md)
- [futures 库](async/futures-crate.md)
- [mio 库](async/mio.md)
- [运行时](async/runtime.md)
- [tokio 库](async/runtime/tokio.md)
- [async-std 库](async/runtime/async-std.md)
- [smol 库](async/runtime/smol.md)
- [如何调试 debug](async/debug.md)
- [](macro/index.md)
- [宏 Macro](macro/macro.md)
- [宏示例](macro/macro-example.md)
Expand Down
11 changes: 10 additions & 1 deletion src/async/async-await.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# 理解 async/await
# 理解 async/await

rustc 编译器遇到 async 函数时, 会在内部生成对应的状态机代码 (state machine), 这个状态机会实现
`Future` trait.

## 参考

- [Understanding Async Await in Rust: From State Machines to Assembly Code](https://eventhelix.com/rust/rust-to-assembly-async-await/)
- [Nested async/await in Rust: Desugaring and assembly](https://eventhelix.com/rust/rust-to-assembly-async-await-nested/)
- [Rust async/await: Async executor](https://eventhelix.com/rust/rust-async-executor/)
6 changes: 6 additions & 0 deletions src/async/debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 如何调试 debug

## 参考

- [tokie-console](https://github.com/tokio-rs/console)
- [Writing a basic `async` debugger](https://cliffle.com/blog/lildb/)
5 changes: 4 additions & 1 deletion src/async/futures-and-tasks.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# 理解 Futures 与 Tasks
# 理解 Futures 与 Tasks

在同步式的代码 (synchronous code) 里调用阻塞函数(blocking function), 会阻塞整个线程;
而在异步式的代码里, `Future` 会把控制权返还给线程, 这样其它的 `Future` 就可以运行了.
2 changes: 2 additions & 0 deletions src/async/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Rust 实现的异步式(async)并发编程模型, 有这些特点:
## 参考

- [Rust async book](https://rust-lang.github.io/async-book/)
- [Async Rust Is A Bad Language](https://bitbashing.io/async-rust.html)
- [Common Mistakes with Rust Async](https://www.qovery.com/blog/common-mistakes-with-rust-async/)
1 change: 1 addition & 0 deletions src/async/lifetimes-pinning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 生命周期与内存保持 Lifetimes and Pinning
1 change: 0 additions & 1 deletion src/async/mem-pinning.md

This file was deleted.

0 comments on commit 593f870

Please sign in to comment.