from Hacker News

Durable Coroutines for Go

by greenSunglass on 10/19/23, 6:45 AM with 35 comments

  • by kitd on 10/20/23, 6:34 PM

    Impressive work. This reminds me of an experimental JVM that was around about 20 years ago from a group called Velare. They could do durable coroutines just like this, but by throwing a particular exception rather than using `yield`. They also could return a value and allow the coro to be resumed with a value.

    edit: here it is https://dl.acm.org/doi/10.1145/949344.949362 It was a built-in bytecode interpreter with suspendable threads

    It changed significantly how you think about cooperating processes. It was like watching 2 processes have a conversation with each other without the controlling code getting involved in any way. Also, if you save the coros after each call, you can get step-by-step replays which are very helpful in debugging.

  • by skybrian on 10/20/23, 7:00 PM

    The saved coroutine state is an implicitly-defined data structure and they don’t support any kind of migration when the code changes, so the durability will be quite limited.
  • by tedunangst on 10/20/23, 6:23 PM

  • by hnav on 10/20/23, 8:27 PM

    I feel like once serializing god-knows-what state across program invocations is a requirement, I'd much prefer writing this explicitly so I can at least have a chance of debugging it

      type Task struct {
        I int
      }
    
      func (t *Task) Next() (bool, int) {
        if t.I < 3 {
          return t.I++, true
        }
        return 0, false
      }
    
      var t Task
      t.Next()
      json.Marshal(t)
  • by zellyn on 10/20/23, 8:30 PM

    A succinct explanation of how durable coroutines are different (in practice) from Temporal would be useful.
  • by ctvo on 10/21/23, 5:21 PM

    From a user perspective: how is this different than what Temporal provides?
  • by born-jre on 10/20/23, 7:09 PM

    nice, but i had a separate idea.

    what if u build a wasm runtime that can save and restore memory with and execution states, sounds much more full proof. or i might have misunderstood this idea :D.

  • by infogulch on 10/20/23, 6:33 PM

    Why are channels insufficient for this use case?
  • by varispeed on 10/20/23, 9:48 PM

    Why not fork Go and implement this directly? (and also removing any telemetry Google might have installed while at it...)
  • by zelly on 10/21/23, 3:09 AM

    This is the kind of thing you can only trust the compiler to do. And we already have goroutines.
  • by rweir on 10/20/23, 10:08 PM

    very cool - looking forward to seeing the rest.