PriorityQueue - Rust #006 - async/await
This video is in French.
In this video, we transform our fair PriorityQueue -- previously entirely synchronous -- into an asynchronous version, driven by Tokio, while keeping the exact same algorithmic core.
Topics covered
- Understanding why the async model is essential when a system spends its time waiting (I/O, timers, network)
- Fundamental difference between threads (preemptive) and tasks (cooperative)
- How async and await actually work: futures, suspension and the role of the runtime
- Why synchronous primitives (Condvar, blocking Mutex) cannot be used in async
- The three building blocks that replace a Condvar:
- Semaphore (available items counter)
- Notify (one-shot event: queue became empty)
- CancellationToken (global best-effort shutdown)
- Internal structure: separation between AsyncState (pure logic state) and AsyncInner (Tokio tools)
- Implementation of methods: enqueue(), dequeue() with tokio::select!, try_dequeue()
Our priority queue is now asynchronous, fair, non-blocking and fully controlled, ready to be integrated into distributed or highly concurrent architectures.
Useful links
Source code: github.com/xigh/pq-async-rs