I had an idea for a way to make generators work over the network and I couldn't get it out of my head so I wrote some proof of concept code:
https://gist.github.com/boutell/59716a582da7c7f4884b
The basic concept is this: each active generator is represented by an object. The object contains the state of the generator, and also contains a "step" function which can be used to generate the next value.
After that the challenge is to serialize this state over the network. To do that, I add a "source" property which is the source code of "step" as obtained via "toString".
Since "step" never relies on a closure, but rather just manipulates the state object that is passed to it on each call, it is possible to reconstruct both the code and the current state of the generator on the receiving end.
The most daunting challenges not answered here:
- The second computer will alter the state of the generator; that must be communicated back to the first computer.
- Each invocation of the generator on either computer should probably result in a network message to the other computer.
- Timing probably matters a whole heckuva lot, since generators can be invoked on every sixteenth note.
But those things are possible in principle with this hack.
I had an idea for a way to make generators work over the network and I couldn't get it out of my head so I wrote some proof of concept code:
https://gist.github.com/boutell/59716a582da7c7f4884b
The basic concept is this: each active generator is represented by an object. The object contains the state of the generator, and also contains a "step" function which can be used to generate the next value.
After that the challenge is to serialize this state over the network. To do that, I add a "source" property which is the source code of "step" as obtained via "toString".
Since "step" never relies on a closure, but rather just manipulates the state object that is passed to it on each call, it is possible to reconstruct both the code and the current state of the generator on the receiving end.
The most daunting challenges not answered here:
But those things are possible in principle with this hack.