3 ms·
spawner.spawn(blinky(led)).unwrap(); Has anyone seriously tried structured concurrency for single-threaded async Rust? The pattern where main effectively leaks
by amluto 3y ago
spawner.spawn(blinky(led)).unwrap();
Has anyone seriously tried structured concurrency for single-threaded async Rust? The pattern where main effectively leaks a task seems kind of gross to me, and it’s exactly what structured concurrency tries to solve.
(I realize that Rust’s async is inherently semi-structured.)
- swsieber 3y agoIIRC been some proposals floating around, but one major block is asncy drop. This is the article I'm thinking of specifically: https://blog.yoshuawuyts.com/tree-structured-concurrency/ https://blog.yoshuawuyts.com/tree-structured-concurrency/
- dirbaio 3y agoYou can use futures combinators like `join`, `select`, `with_timeout` with async Rust. (crates like `embassy-futures` or `futures` have implementations of these). They work nicely even in no-std embedded. They're different tools for different use cases. Structured concurrency is nice when doing related actions concurrently where one might need to cancel the other, while unstructured task spawning makes more sense if they're truly unrelated tasks, that live for the entire duration of the program or where you don't care for how long they live (for example concurrently handling requests in a server). (disclaimer: Embassy maintainer here)