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!

  • dillekant@slrpnk.net
    link
    fedilink
    English
    arrow-up
    5
    ·
    1 year ago

    Wait is there a difference between coroutines and async/await? I thought they were practically the same model.

    • chrysn@chaos.social
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      Coroutines are one means of implementing async; the way they are implemented in Rust is more like building a state machine out of the async function. It can still be mapped to coroutines, and there are probably crates that use async and macros to make coroutines usable on stable, but the effort to have a stable language feature is still ongoing, with https://lang-team.rust-lang.org/design_notes/general_coroutines.html giving the overview.

    • runiq@lemmyrs.org
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      Someone please correct me because I’m fairly sure I’m not entirely correct here, but IIRC from the ‘Programming Lua’ book, (symmetric) coroutines allow you to pass data back into the routine at the await point. Or, in Lua parlance, coroutine.resume() can take arguments.

  • netwren@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 year ago

    Super interested to see if this is true as well. AFAIK Rust focuses on threading and async/await with Tokio being the main focus.

    I believe there is some support of green threads with Tokio configuration but I’m not 100% sure and am just writing off the top of my head because nobody has responded yet.