Tokio (software)

From Wikipedia, the free encyclopedia
Tokio
Tokio logo.svg
Initial releaseDecember 23, 2020; 14 months ago (2020-12-23)
Stable release1.14.0[1] Edit this on Wikidata (22 November 2021; 3 months ago (22 November 2021))
Repository
Written inRust
LicenseMIT License
Websitetokio.rs

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[]

  1. ^ "Release 1.14.0". 22 November 2021. Retrieved 28 November 2021.
  2. ^ 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.
  3. ^ 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.
  4. ^ 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.
  5. ^ 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)
  6. ^ "Rust Gets Zero-Cost Async/Await Support in Rust 1.39". InfoQ. Retrieved 2021-11-28.
  7. ^ "The Async Ecosystem". Asynchronous Programming in Rust. Retrieved 2021-11-28.{{cite web}}: CS1 maint: url-status (link)
  8. ^ 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)
  9. ^ Matsakis, Niko (2019-11-07). "Async-await on stable Rust!". Rust Blog. Retrieved 2021-11-28.{{cite web}}: CS1 maint: url-status (link)
  10. ^ "Hello Tokio". Tokio. Retrieved 2021-11-28.{{cite web}}: CS1 maint: url-status (link)
  11. ^ "Announcing tokio-uring: io-uring support for Tokio". Tokio. Retrieved 2021-11-28.{{cite web}}: CS1 maint: url-status (link)
  12. ^ Lerche, Carl (2016-08-03). "Announcing Tokio". Medium. Retrieved 2021-11-21.
  13. ^ "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)
  14. ^ "Announcing Tokio 1.0". Tokio. Retrieved 2021-11-28.{{cite web}}: CS1 maint: url-status (link)
  15. ^ "Welcoming Alice Ryhl as the first paid Tokio contributor". Tokio. Retrieved 2021-11-28.{{cite web}}: CS1 maint: url-status (link)
  16. ^ Allen Wyma (12 November 2021). "Tokio Ecosystem with Alice Ryhl". Rustacean Station (Podcast). Retrieved 2021-11-26.

External links[]

Retrieved from ""