Skip to content

Commit

Permalink
Add runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
weipin committed Jan 10, 2025
1 parent 1b09dfc commit 5e29879
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
- [Lifecycle](basic/waker/lifecycle.md)
- [std::task::Waker](basic/waker/rust.md)
- [Examples](basic/waker/examples.md)
- [Scheduler]()
- [Runtime]()
- [Runtime](basic/runtime/readme.md)
- [Composing]()
- [async and await]()

Expand Down
21 changes: 21 additions & 0 deletions src/basic/runtime/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Runtime

A runtime provides what Rust left. Only with a runtime, async Rust can actually
be used to program.

## Features

Runtimes are all third-party. Some of the major features they provide:

1. Future implementations.
1. Reactor implementations.
1. Managing Futures.
1. Managing Wakers.
1. Scheduling Future polling.
1. Utilities.

## Links

1. [Tokio](https://github.com/tokio-rs/tokio)
1. [smol](https://github.com/smol-rs/smol)
1. [Embassy](https://github.com/embassy-rs/embassy)
4 changes: 2 additions & 2 deletions src/basic/waker/reactor.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Reactor, handling I/O event notifications

## Question
How can a waker **effectively** knows when its data is ready?
How can a waker **efficiently** knows when its data is ready?

## Answer
"Effectively" means no loop. In other words, a waker should be *notified* when
"efficiently" means no loop. In other words, a waker should be *notified* when
its data is ready. Such effectiveness is often achieved by using the
notification mechanisms provided by the operating systems.

Expand Down
6 changes: 3 additions & 3 deletions src/basic/waker/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ RawWakers function like [Trait Objects][6]. The [RawWakerVTable][7] provides a
common behavior, and the `*const ()` pointer stores arbitrary data that the
common behavior applies on.

Benefits of the "vtable strategy":
1. Breaking away from the requirements that [dyn compatibility][8] (formerly
While inconvenient, this "vtable strategy" has its benefits:
1. Breaks away from the requirements that [dyn compatibility][8] (formerly
"object safety") enforces.
1. [Reducing allocations][9].
1. Enables [reducing allocations][9].


[1]: https://doc.rust-lang.org/std/task/struct.Waker.html
Expand Down
10 changes: 5 additions & 5 deletions src/basic/waker/waking.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Waking, pushing futures in a polling queue
# Waking, pushing futures to a polling queue

## Question
How can a waker have its future "polled"?

## Answer
A waker calls specific "waking" code when the waker is notified that its data
is ready. The "waking" code locates the future that the waker associates to,
and push the future to a "polling queue".
and pushes the future to a "polling queue". A waker's job is finished after
"waking".

A waker's job is finished after "waking". With a "polling queue", wakers are
decoupled from "external code" which pops futures from the queue, polls the
futures and handles data.
With a "polling queue", wakers are decoupled from "external code" which pops
futures from the queue, polls the futures and dispatches data.

Diagram: a waker wakes.
```d2
Expand Down

0 comments on commit 5e29879

Please sign in to comment.