Tokio (software)
Tokio is a software library for the Rust programming language.[src] It provides a runtime and functions that enable the use of asynchronous I/O, allowing for concurrency in regards to task completion.[src] Tokio was released in August 2016 for Rust, a general-purpose programming language.[src] Developed by Carl Lerche, Tokio began as a network application framework and supports features such as socket listening and broadcasting, allowing messages to be transferred between computers.[src]
Tokio is a software library for the Rust programming language.[src] It provides a runtime and functions that enable the use of asynchronous I/O, allowing for concurrency in regards to task completion.[src] Tokio was released in August 2016 for Rust, a general-purpose programming language.[src] Developed by Carl Lerche, Tokio began as a network application framework and supports features such as socket listening and broadcasting, allowing messages to be transferred between computers.[src] ==Features== ===Runtime=== Tokio allows for the execution of asynchronous functions in Rust through its built-in runtime, which may be initialized via the #[tokio::main] macro.[src] For example: use std::error::Error; [tokio::main] async fn main() -> Result > { let url = "https://en.wikipedia.org/"; let text = reqwest::get(url).await?.text().await?; println!("{}", text); Ok(()) } Here, the reqwest crate is used to request the HyperText Markup Language (HTML) for English Wikipedia.[src] After reqwest::get is called to initialize the asynchronous request, .await will hand over control to the runtime, which then drives all the I/O operations of the request to completion before resuming the main function after the .await .[src] A simple example of a TCP echo server is as follows: use std::error::Error; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::net::TcpListener; [tokio::main] async fn main() -> Result > { // Run a server on port 8080.[src] let listener = TcpListener::bind("localhost:8080").await?; loop { // Wait for a new connection from a client.[src] let (mut stream, _remote_addr) = listener.accept().await?; // Spawn a new asynchronous task to handle the connection.[src] tokio::spawn(async move { let (reader, mut writer) = stream.split(); let mut reader = BufReader::new(reader); // While there is data to be read from the stream… while !reader.fill_buf().await.unwrap().is_empty() { // Write the data back.[src] writer.write_all(reader.buffer()).await.unwrap(); } }); } } This code makes use of the tokio::spawn function to create an asynchronous task (implemented as a stackless coroutine), allowing each connection to be handled separately in the same process, as the runtime ensures that tasks run in the background automatically.[src] Importantly however, the runtime multiplexes the tasks’ execution on a single thread pool (whose size is by default equal to the number of processors on the system), and so in comparison to the approach of spawning a separate thread for each task, fewer resources are consumed.[src] ===Asynchronous I/O and timers=== Tokio provides several I/O and timing primitives that work natively inside its runtime.[src] The TcpListener structure used above contains a Transmission Control Protocol (TCP) socket listener that is registered with the runtime, allowing it to be used asynchronously; similarly, the tokio::time::sleep function can be used to suspend a task's execution for a certain duration of time, and again this is implemented by registration with the runtime.[src] ===Synchronization primitives=== Tokio also provides several generic synchronization primitives suitable for use in an asynchronous context, including locks, semaphores, barriers and channels.[src] Unlike the I/O and timer primitives, these work even outside of the runtime context.[src] ===Blocking thread pool=== To facilitate interopability with traditional synchronous code, Tokio provides as part of its runtime a thread pool on which synchronous I/O operations may run.[src] In particular, tokio::task::spawn_blocking creates a task which runs in this pool, and is allowed to perform blocking operations—this is unlike tokio::spawn , which may only run asynchronous code.[src] For example, this is used to implement filesystem operations, as many platforms do not provide native asynchronous filesystem APIs (an exception to this is Linux's io_uring , however support for this exists only in the external tokio_uring library and is not yet built in).[src]
24 sentences · 24 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Tokio (software)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/tokio-software. Accessed 03 December 2026.
Chicago
"Tokio (software)." encyclopegia.org. Accessed December 3, 2026. https://encyclopegia.org/wiki/tokio-software.
APA
encyclopegia.org. (2026). Tokio (software). Retrieved December 3, 2026, from https://encyclopegia.org/wiki/tokio-software
Accessed December 3, 2026 · CC BY-SA 4.0 · citation page · JSON
Claims
| Predicate | Value | Source |
|---|---|---|
| release date | 2016 | Wikipedia |