this post was submitted on 06 Jul 2023
6 points (100.0% liked)

Rust Lang

148 readers
1 users here now

Rules [Developing]

Observe our code of conduct

Constructive criticism only

No endless relitigation

No low-effort content

No memes or image macros

No NSFW Content

founded 1 year ago
MODERATORS
 

I’m just starting to learn Rust, and was wondering if there is a good way to do coroutines/channels. I’ve grown fond of languages based around CSP, but am not sure that maps well to idiomatic Rust.

Thanks in advance!

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 8 points 1 year ago* (last edited 1 year ago) (1 children)

One approach I'm personally fond of is actor-style async programming with tokio. It's easy to mingle timers with receiving messages from channels, which is quite powerful. This post by Alice Rhyl is a good description of the idea: https://ryhl.io/blog/actors-with-tokio/

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago)

This.

tokio tasks are green threads. https://docs.rs/tokio/latest/tokio/task/

tokio also offers a variety of channels for synchronization between tasks. https://docs.rs/tokio/latest/tokio/sync/index.html