Durable Coroutines for Go

by greenSunglasson 10/19/2023, 6:45 AMwith 35 comments

by kitdon 10/20/2023, 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 skybrianon 10/20/2023, 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 tedunangston 10/20/2023, 6:23 PM

This seems really brittle.

https://github.com/stealthrocket/coroutine/blob/main/getg_am...

by hnavon 10/20/2023, 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 zellynon 10/20/2023, 8:30 PM

A succinct explanation of how durable coroutines are different (in practice) from Temporal would be useful.

by ctvoon 10/21/2023, 5:21 PM

From a user perspective: how is this different than what Temporal provides?

by born-jreon 10/20/2023, 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 infogulchon 10/20/2023, 6:33 PM

Why are channels insufficient for this use case?

by varispeedon 10/20/2023, 9:48 PM

Why not fork Go and implement this directly? (and also removing any telemetry Google might have installed while at it...)

by zellyon 10/21/2023, 3:09 AM

This is the kind of thing you can only trust the compiler to do. And we already have goroutines.

by rweiron 10/20/2023, 10:08 PM

very cool - looking forward to seeing the rest.