Is it possible to serialize a generator in JavaScript? Deserialize from disk and continue its computation? If not, is there any other mainstream language that supports such feature?
Not in Javascript (April 2020).
The feature you're describing is sometimes called 'coroutine with snapshot' or 'serializable first-class continuations.'
Scala had some attempts with this but seemed mostly abandoned. see http://storm-enroute.com/coroutines/docs/0.6/snapshots/.
Java's project loom also seems to include the ability to serialize continuations.
Additionally, in Wikipedia, there is a list of languages supporting first-class continuations. It doesn't specify which ones can also create snapshots/serialization, but it seems like a good start.
One last thing, in many cases, you can simply define the logic you want in a way that derives from the state without the need of any special language features requirements (i.e., state-charts, workflow graphs, rule engines, etc.,)
(that is the reason the feature you're describing is often missing in programming languages. It is complicated to implement and it is generally rare to find use-cases that don't have reasonable alternatives)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With