Tokio (software)
![]() | |
Initial release | December 23, 2020 |
---|---|
Stable release | 1.14.0[1] ![]() |
Repository | |
Written in | Rust |
License | MIT License |
Website | tokio |
Tokio is a software library for the Rust programming language. It provides a runtime and functions that enable the use of asynchronous I/O.[2][3][4][5]
Overview[]
While Rust has supported asynchronous functions since version 1.39 which was released in November 2019,[6] it requires an external runtime to execute them.[7] Tokio provides a runtime that uses a multi-threaded work stealing scheduler.[8] Rust's futures are lazily evaluated, requiring functions to call .await
before they do any work.[9] When .await
is invoked, Tokio's runtime may pause the original future until its I/O completes, and unpauses a different task that is ready for further processing.[10] A basic Tokio program that fetches a webpage looks like the following:
#[tokio::main]
async fn main() -> Result<()> {
let url = "https://en.wikipedia.org/";
let text = reqwest::get(url).await?.text().await?;
println!("{}", text);
Ok(())
}
The #[tokio::main]
macro transparently creates a Tokio runtime to execute the program with.
Tokio further allows users to create tasks, which are green threads, using a tokio::spawn()
function. Unlike futures, tasks do not need to use .await
, as the task will be automatically executed when a thread is available.
Tokio also includes a version of the Rust standard library that is designed for being used asynchronously. For example, tokio::fs::read_to_string()
, which reads the contents of a file, is the asynchronous version of std::fs::read_to_string()
.
Tokio supports io_uring, a Linux asynchronous I/O syscall interface, in a separate crate named tokio-uring
.[8][11]
History[]
Tokio was first announced in 2016 as a framework for building fast network applications.[12] In 2017, Tokio received a grant from the Mozilla Open Source Support fund.[13]
Tokio 0.3 was released in October 2020, and treated as a beta release preceding an eventual 1.0 stable release. Tokio 1.0 was released in December 2020 and will be supported for at least five years.[8][14]
Notable users of Tokio include the development teams behind Discord and AWS Lambda.[8] In April 2021, Tokio funded its first paid contributor, Alice Ryhl.[15][16]
References[]
- ^ "Release 1.14.0". 22 November 2021. Retrieved 28 November 2021.
- ^ Chanda, Abhishek (2018). Network Programming with Rust : Build fast and resilient network servers and clients by leveraging Rust's memory-safety and concurrency features. Birmingham: Packt Publishing. ISBN 978-1-78862-171-7. OCLC 1028194311.
- ^ Eguia Moraza, Iban (2018). Rust high performance : learn to skyrocket the performance of your Rust applications. Birmingham, UK. ISBN 978-1-78847-823-6. OCLC 1033544275.
- ^ Sharma, Rahul (2019). Mastering Rust : learn about memory safety, type system, concurrency, and the new features of Rust 2018 edition. Vesa Kaihlavirta (Second ed.). Birmingham, UK. ISBN 978-1-78934-118-8. OCLC 1090681119.
- ^ De Simone, Sergio (2021-01-06). "Rust Asynchronous Runtime Tokio Reaches 1.0". InfoQ. Retrieved 2021-11-21.
{{cite web}}
: CS1 maint: url-status (link) - ^ "Rust Gets Zero-Cost Async/Await Support in Rust 1.39". InfoQ. Retrieved 2021-11-28.
- ^ "The Async Ecosystem". Asynchronous Programming in Rust. Retrieved 2021-11-28.
{{cite web}}
: CS1 maint: url-status (link) - ^ a b c d Krill, Paul (2021-01-08). "Tokio Rust runtime reaches 1.0 status". InfoWorld. Retrieved 2021-09-03.
{{cite web}}
: CS1 maint: url-status (link) - ^ Matsakis, Niko (2019-11-07). "Async-await on stable Rust!". Rust Blog. Retrieved 2021-11-28.
{{cite web}}
: CS1 maint: url-status (link) - ^ "Hello Tokio". Tokio. Retrieved 2021-11-28.
{{cite web}}
: CS1 maint: url-status (link) - ^ "Announcing tokio-uring: io-uring support for Tokio". Tokio. Retrieved 2021-11-28.
{{cite web}}
: CS1 maint: url-status (link) - ^ Lerche, Carl (2016-08-03). "Announcing Tokio". Medium. Retrieved 2021-11-21.
- ^ "Mozilla Awards $365,000 to Open Source Projects as part of MOSS". LWN.net. Retrieved 2021-11-21.
{{cite web}}
: CS1 maint: url-status (link) - ^ "Announcing Tokio 1.0". Tokio. Retrieved 2021-11-28.
{{cite web}}
: CS1 maint: url-status (link) - ^ "Welcoming Alice Ryhl as the first paid Tokio contributor". Tokio. Retrieved 2021-11-28.
{{cite web}}
: CS1 maint: url-status (link) - ^ Allen Wyma (12 November 2021). "Tokio Ecosystem with Alice Ryhl". Rustacean Station (Podcast). Retrieved 2021-11-26.
External links[]
- Official website
- Tokio on GitHub
- Tokio on crates.io
- Free software programmed in Rust
- Free computer libraries