
Tokio Semaphores for Limiting Concurrency in Rust Services
A Semaphore hands out a fixed number of permits so only N tasks run a section at once. See acquire, owned permits, fairness and common limits to set.
Threads, channels, locks, atomics and Tokio, with a bias towards the bug you will hit at 3am.

A Semaphore hands out a fixed number of permits so only N tasks run a section at once. See acquire, owned permits, fairness and common limits to set.

Share state in async code with Arc<Mutex<T>>, with a state owning task and channels, or with read heavy structures. See the trade-offs and the failure modes.

A bounded channel makes a fast producer wait for a slow consumer. See capacity, send().await, try_send, and how to choose a size that does not hide overload.

Shut down a Tokio service cleanly: catch SIGTERM and Ctrl+C, stop accepting work, wait for in flight tasks with TaskTracker, then exit within a deadline.

Stop a Tokio task three ways: JoinHandle::abort, a CancellationToken for cooperative shutdown, and dropping a future. See what each does to cleanup.

select! races futures and drops the losers, which is only safe if they can be dropped mid way. Learn what cancellation safe means and which APIs are not.

Both move blocking work off the async threads, but they differ in pool, limits and fit. See which to pick for file I/O, hashing and number crunching.

JoinSet owns a group of spawned tasks and returns their results as they finish. See spawn, join_next, abort_all and how errors and panics surface.

tokio::spawn demands a future that owns its data. Learn why the compiler asks for static, what it does and does not mean, and four ways to share data with a task.

async and await are syntax over futures. Learn what async blocks capture, where await may appear, how errors and ? work, and the common first mistakes.

An async fn compiles to a state machine that implements Future. See the generated shape, what poll does, and why a future does nothing until it is polled.

Spawn tasks with tokio::spawn, wait for them with JoinHandle and collect results with JoinSet. Includes the Send and static bounds and the panics join returns.
We send one email when a new post is published. No spam.