4 ms·
The one big issue I have with coroutines is that they are often impossible to serialize. With a state machine you can just take your state and write it to disk,
by grumbel 3y ago
The one big issue I have with coroutines is that they are often impossible to serialize. With a state machine you can just take your state and write it to disk, but with coroutines that state is hidden in the stack of the coroutine and the stack is not a first-class data structure you can access by normal programming language means.
- OskarS 3y agoStackless coroutines are arguably pretty serializable, since they are (usually) implemented by bundling all the relevant data into a struct. There’s no a priori reason that couldn’t be serialized, thiugh I admit I cannot think of an example I’ve seen it used.
- clavigne 3y agoWe use it at work to send FSMs over the network for distributing tasks. Admittedly we always do this with continuations that haven't started yet, but there is no technical reason we couldn't serialize the already started ones (although you'd have to make sure you also send the coroutines you are currently awaiting on.)