this post was submitted on 08 Sep 2023
44 points (90.7% liked)

Rust

6005 readers
5 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] wim@lemmy.sdf.org 12 points 1 year ago (11 children)

Maybe it's just me, but isn't async programming a mess in all programming languages?

[–] noli@programming.dev 0 points 1 year ago (10 children)

It's a joy to do async in go IMO

[–] sugar_in_your_tea@sh.itjust.works 1 points 1 year ago (2 children)

To be fair, a lot of that is because the scheduler detects blocking IO and context switches.

Rust could get really far with Go-style channels.

[–] realharo@lemm.ee 1 points 1 year ago (1 children)

Are Go-style channels different from what Tokio provides? https://tokio.rs/tokio/tutorial/channels

They're very similar, but with very different ergonomics. Go channels are part of the language, so libraries use them frequently, whereas tokio is a separate library and not nearly as ubiquitous. So you'll get stuff like this:

c := make(chan bool)
go func () {
    time.Sleep(time.Second*2)
    c <- true
} ()

select {
case val := <-c:
case _ := <-time.After(time.Second)
}

This lets you implement a simple timeout for a channel read. So the barrier to using them is really low, so they get used a ton.

I haven't looked at the implementation of tokio channels, so I don't know if there's something subtly different, but they do have the same high level functionality.

load more comments (7 replies)
load more comments (7 replies)