this post was submitted on 28 Jan 2024
676 points (94.8% liked)

Programmer Humor

32483 readers
518 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 7 points 9 months ago (41 children)

I honestly don't know, why async got so popular. It seems like the entire reason for doing it was that some blokes were hellbent on using JS on a server and couldn't fathom that a second thread might be a good idea.

[–] [email protected] 10 points 9 months ago* (last edited 9 months ago) (2 children)

Async rust with the Tokio Framework is pretty cool. Need none of that JS bloat for async.

[–] [email protected] 3 points 9 months ago (2 children)

Honestly I can't wrap my head how to effectively put computation into a thread, even with Tokio.

All I want is something like rayon where you got a task queue and you just yeet tasks into a free thread, and await when you actually need it

Might be too much JS/TS influence on me, or that I can't find a tutorial that would explain in a way that clicks for me

[–] [email protected] 3 points 9 months ago

Tokio specifically says not to use it for CPU intensive tasks and rayon would be better for this: https://tokio.rs/tokio/tutorial

Speeding up CPU-bound computations by running them in parallel on several threads. Tokio is designed for IO-bound applications where each individual task spends most of its time waiting for IO. If the only thing your application does is run computations in parallel, you should be using rayon. That said, it is still possible to "mix & match" if you need to do both. See this blog post for a practical example

[–] [email protected] 1 points 9 months ago

Tokio is for concurrency, not parallelism. Use it for IO stuff. They say rayon is good for that, but I haven't used that. If you just want something simple, I'd recommend working with threadpool.

load more comments (38 replies)