---
source: https://iinventedlight.com/library/notes/rust-tokio-spawn.md
title: "tokio::spawn runs an async block as a task; it must be 'static and Send"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Tokio tutorial); MIT (tokio-rs/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Tokio tutorial, Spawning; tokio-rs/website (GitHub), spawning.md (source page). MIT (https://raw.githubusercontent.com/tokio-rs/website/master/LICENSE). Copyright Tokio contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: tokio spawn"
tags: [rust, tokio, spawn, joinhandle, send, static, concurrency]
client: Librarian
sources:
  - id: S1
    title: "Spawning"
    publisher: Tokio tutorial
    url: https://tokio.rs/tokio/tutorial/spawning
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "spawning.md (source page)"
    publisher: tokio-rs/website (GitHub)
    url: https://github.com/tokio-rs/website/blob/master/content/tokio/tutorial/spawning.md
    accessed: 2026-11-18
    license: "MIT"
---
# tokio::spawn runs an async block as a task; it must be 'static and Send
**Answer:** Pass an async block to `tokio::spawn`; it returns a `JoinHandle`, and `.await` on the handle gives a `Result` with the block's return value. The spawned task must be `'static` (use `async move` so it owns its data) and `Send` (everything held across an `.await` must be `Send`).

## Example

```rust
#[tokio::main]
async fn main() {
    let handle = tokio::spawn(async {
        "return value"
    });
    let out = handle.await.unwrap();
    println!("GOT {}", out);
}
```

A server spawns a new task for each inbound socket and moves the socket into it:
```rust
loop {
    let (socket, _) = listener.accept().await.unwrap();
    tokio::spawn(async move { process(socket).await; });
}
```

## Errors from the JoinHandle

Awaiting on `JoinHandle` returns a `Result`. It is an `Err` when the task panics or when the runtime shutting down forcefully cancels the task.

## The 'static bound

The spawned task must not contain any references to data owned outside the task. By default, variables are not moved into async blocks; `async move` will instruct the compiler to move `v` into the spawned task, so the task owns all of its data. If a single piece of data must be accessible from more than one task concurrently, share it with synchronization primitives such as `Arc`.

## The Send bound

`Send` allows the Tokio runtime to move the tasks between threads while suspended at an `.await`. A task is `Send` when all data that is held across `.await` calls is `Send`. An `Rc` dropped before the `.await` is fine; an `Rc` used after it makes the task not `Send`.

## Cost

Tasks in Tokio are very lightweight: under the hood, each one needs only a single allocation and 64 bytes of memory, so spawning thousands, if not millions of tasks is fine.

## See also

- [rust-tokio-main-macro](https://iinventedlight.com/library/notes/rust-tokio-main-macro/)
- [rust-mutex-arc-send-sync](https://iinventedlight.com/library/notes/rust-mutex-arc-send-sync/)
- [rust-async-await-futures](https://iinventedlight.com/library/notes/rust-async-await-futures/)

## Claims

- id: C1
  claim: tokio::spawn returns a JoinHandle.
  source: S1
  evidence: "The tokio::spawn function returns a JoinHandle"

- id: C2
  claim: Spawned tasks must implement Send.
  source: S2
  evidence: "Tasks spawned by `tokio::spawn` **must** implement `Send`."

- id: C3
  claim: Each task needs a single allocation and 64 bytes.
  source: S2
  evidence: "they require only a single allocation and 64 bytes of memory"

## Sources

- [S1] Spawning. Tokio tutorial. https://tokio.rs/tokio/tutorial/spawning . License: MIT. Accessed 2026-11-18.

- [S2] spawning.md (source page). tokio-rs/website (GitHub). https://github.com/tokio-rs/website/blob/master/content/tokio/tutorial/spawning.md . License: MIT. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Tokio tutorial, Spawning; tokio-rs/website (GitHub), spawning.md (source page). MIT (https://raw.githubusercontent.com/tokio-rs/website/master/LICENSE). Copyright Tokio contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
