5 ms·
Does anybody have a good solution for the "Sharing Coroutine State Sucks"-problem? I've thought a very long time about this (in my case, using continuations in
by chriseidhof 16y ago
Does anybody have a good solution for the "Sharing Coroutine State Sucks"-problem? I've thought a very long time about this (in my case, using continuations in FP instead of coroutines in Lua), but I still can't seem to come up with a good answer.
I guess one way to deal with it is by mechanically transforming the co-routines into a FSM. This is very similar to defunctionalization. However, I don't know of a language that does this well. Any suggestions?
- mprovost 16y agoWith Stackless Python you can pickle (serialize) tasklets (coroutines). I built a Seaside-style web app in Stackless where each response would get pickled and saved to disk. When a new request with that id comes in you just unpickle it back into a tasklet and resume where you left off. You can do this between processes and machines. I don't see why you couldn't put them in a db but I was just using shared disk. What you're looking for are serializable continuations which some languages can handle.
- chriseidhof 16y agoVery impressive. I'll have to look into that.
- deleted 16y ago[deleted]
- silentbicycle 16y agoYou can build a FSM using tail calls. (Lua has TCO.) It's really common to do this in Erlang, too. It's also possible to stream Lua functions, though it's a bit tricky to do with closures.
- tomjen3 16y agoYou can send functions to Erlang processes for execution, so it shouldn't be that hard to do. The only problem you end up with then is that Erlang is one extreemly ugly little language.