Skip to content

Commit

Permalink
Add task
Browse files Browse the repository at this point in the history
  • Loading branch information
weipin committed Jan 23, 2025
1 parent e0e2a92 commit c0c163d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
- [Join](advanced/composing/join.md)
- [Select](advanced/composing/select.md)
- [Future Tree](advanced/composing/tree.md)
- [Procedural](advanced/composing/procedural.md)
- [async and await](advanced/async_await/readme.md)
- [Size](advanced/async_await/size.md)
- [Exercises](advanced/async_await/exercises.md)
- [Task]()
- [Task](advanced/task/readme.md)
- [Mutex]()
- [Stream]()

Expand Down
9 changes: 9 additions & 0 deletions src/advanced/composing/procedural.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Procedural

A Future (tree) is procedural.

Externally, as a whole, a Future is "single-threaded" -- at any given time, a
Future should be polled in *one* thread.

Internally, as a tree of Futures, the Futures involved in the "current external
poll" should be polled *one by one*, in the given thread.
19 changes: 19 additions & 0 deletions src/advanced/task/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Task

## Internally

Runtimes use Tasks internally to manage Futures. A Task is an object which
contains a Future and "everything else" needed to manage the Future.


## Externally

While "Task" is internal to a runtime, knowing that it exists can help us
understand the runtimes better, and thus use them well.

Like a Future, a Task is also [procedural](../composing/procedural.md). To have
Futures polled in a "multi-threaded" way, they must be spawned (see
[smol::spawn][1] or [tokio::task::spawn][2]).

[1]: https://docs.rs/smol/latest/smol/fn.spawn.html
[2]: https://docs.rs/tokio/latest/tokio/task/fn.spawn.html

0 comments on commit c0c163d

Please sign in to comment.