diff --git a/docs/src/concepts/tasks.md b/docs/src/concepts/tasks.md index 189ee13..a56cff5 100644 --- a/docs/src/concepts/tasks.md +++ b/docs/src/concepts/tasks.md @@ -45,12 +45,14 @@ This is an `async` *block*. Async blocks are necessary to call `async` functions But let’s get to the interesting part: ```rust + task::spawn(async { }) + ``` `spawn` takes a Future and starts running it on a `Task`. It returns a `JoinHandle`. Futures in Rust are sometimes called *cold* Futures. You need something that starts running them. To run a Future, there may be some additional bookkeeping required, e.g. if it’s running or finished, where it is being placed in memory and what the current state is. This bookkeeping part is abstracted away in a `Task`. A `Task` is similar to a `Thread`, with some minor differences: it will be scheduled by the program instead of the operating system kernel and if it encounters a point where it needs to wait, the program itself responsible for waking it up again. We’ll talk a little bit about that later. An `async_std` task can also has a name and an ID, just like a thread. -For now, it is enough to know that once you `spawn`ed a task, it will continue running in the background. The `TaskHandle` in itself is a future that will finish once the `Task` ran to conclusion. Much like with `threads` and the `join` function, we can now call `block_on` on the handle to *block* the program (or the calling thread, to be specific) to wait for it to finish. +For now, it is enough to know that once you `spawn`ed a task, it will continue running in the background. The `JoinHandle` in itself is a future that will finish once the `Task` ran to conclusion. Much like with `threads` and the `join` function, we can now call `block_on` on the handle to *block* the program (or the calling thread, to be specific) to wait for it to finish. ## Tasks in `async_std` @@ -59,7 +61,7 @@ Tasks in `async_std` are one of the core abstractions. Much like Rust’s `threa - They are single-allocated -- All tasks have a *backchannel*, which allows them to propagate results and errors to the spawning task through the `TaskHandle` +- All tasks have a *backchannel*, which allows them to propagate results and errors to the spawning task through the `JoinHandle` - The carry desirable metadata for debugging - They support task local storage