Crates/Tokio
16 articles
How to create a TCP server
Build a TCP server in Rust by binding a TcpListener, accepting connections, and handling each one in its own thread or async task. Walk through echo, line-protocol, and concurrency patterns.
How to create a UDP server
Create a UDP server in Rust by binding a UdpSocket to an address and looping through recv_from calls to process incoming data.
How to gracefully shutdown async tasks in tokio
Gracefully shutdown Tokio async tasks by awaiting their JoinHandles or using select! to cancel them on a shutdown signal.
How to Profile Async Rust Applications (tokio-console)
tokio-console is a live, top-style dashboard for async Rust. Wire in the console-subscriber crate, run your app with the right cfg flag, and watch tasks, polls, and stalls in real time.
How to Set Up the Tokio Runtime in Rust
Set up the Tokio runtime in Rust by using the trpl::block_on helper to execute async functions.
How to use tokio broadcast channel
Create a broadcast channel with tokio::sync::broadcast::channel to send messages from one sender to multiple async receivers.
How to use tokio crate in Rust async runtime
Tokio is Rust's most-used async runtime. Walk through #[tokio::main], spawning concurrent tasks, a TCP echo server, and the blocking-call trap that catches every beginner.
How to use tokio mpsc channel
Create an async channel with trpl::channel, send data via tx.send, and receive it with rx.recv.await inside a Tokio runtime.
How to use tokio oneshot channel
Create a one-time message channel in Rust using tokio::sync::oneshot::channel() to send data between async tasks.
How to use tokio select macro
The tokio::select! macro runs multiple futures concurrently and executes the code block for whichever one finishes first.
How to use tokio spawn
Use tokio::task::spawn to run async functions concurrently and get a JoinHandle to await their results.
How to Use tokio::spawn for Spawning Async Tasks
Use tokio::spawn to run async code in the background and get a handle to retrieve the result later.
How to use tokio sync Semaphore
Limit concurrent async tasks in Rust by acquiring a permit from a tokio::sync::Semaphore before entering a critical section.
How to use tokio watch channel
Use tokio::sync::watch::channel to broadcast the latest value to multiple async receivers efficiently.
What is the tokio runtime
The Tokio runtime is the engine that executes asynchronous Rust code by scheduling tasks and managing resources efficiently.
What is tokio task JoinSet
A JoinSet manages multiple async tasks and yields results as they complete.