diff --git a/src/SUMMARY.md b/src/SUMMARY.md index b719846..a0ac05f 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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]() diff --git a/src/advanced/composing/procedural.md b/src/advanced/composing/procedural.md new file mode 100644 index 0000000..f8ce68d --- /dev/null +++ b/src/advanced/composing/procedural.md @@ -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. diff --git a/src/advanced/task/readme.md b/src/advanced/task/readme.md new file mode 100644 index 0000000..d1dbf80 --- /dev/null +++ b/src/advanced/task/readme.md @@ -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