Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pickle/Serialize generator state in JavaScript

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?

like image 878
Alejandro Navas Avatar asked Oct 25 '25 18:10

Alejandro Navas


1 Answers

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)

like image 59
Amit Portnoy Avatar answered Oct 28 '25 07:10

Amit Portnoy