Learning Rust Async | Not Live Stream ⏺️
Автор: Learning Rust
Загружено: 2025-04-03
Просмотров: 341
Learning tokio async / join / join set
This a "mistakes and all" attempt at learning some new async stuff
"Async is great for AI/LLM projects because it handles many tasks at once without blocking. While waiting for a response (like from an API or database), async lets other tasks run. This makes chatbots, data pipelines, and AI services faster and more efficient."
"Asynchronous programs in Rust are based around lightweight, non-blocking units of execution called tasks. The tokio::task module provides important tools for working with tasks"
If you want the code, and the article :
🔗 https://redandgreen.co.uk/tokio-async...
async book
🔗 https://rust-lang.github.io/async-boo...
official tokio tutorial
🔗 https://tokio.rs/tokio/tutorial
tokio crate documentation + example
🔗 https://docs.rs/tokio/latest/tokio/#w...
#learningrust #AsyncRust
Tokio async in rust example
Tokio's multi-threaded runtime, tasks will be scheduled across multiple threads.
Tokio's work-stealing scheduler will distribute tasks among available threads to maximize efficiency.
Awaiting tasks:
------------------------
For awaiting multiple tasks in Tokio, the best approach depends on your specific needs:
~ Using join_all from the futures crate is generally the best option when you need to:
Wait for all tasks to complete before proceeding
Keep your code concise
Collect all results at once
~ The individual handle.await approach is better when you need to:
Process each task's result immediately as it completes
Handle errors individually with custom logic
Do something between each task completion
~ tokio::JoinSet is best when you have a dynamic set of tasks where you:
Need to add/remove tasks during execution
Want to process results in completion order (not spawn order)
Need to limit concurrency
For most simple cases where you spawn a known number of tasks and need to wait for all of them, join_all provides the cleanest and most efficient solution with the least boilerplate code.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: