Closed fbinz closed 10 years ago
Yes, this is a known issue, and in fact a conceptual problem. The effectful
signal gets garbage collected because its output is not used. The solution is to keep the thread alive by adding the dummy signal returned by the constructor to the data-flow network in a way that won’t affect the output; liftA2 const
does the trick. For instance, we needed to do this when building an Elerea interface over the Bullet physics engine:
http://lambdacube3d.wordpress.com/2012/11/16/using-bullet-physics-with-an-frp-approach-part-2/
You can think of the dummy signal as an object that represents the effectful thread. In order to kill the thread, you need to detach the dummy signal from the network. I’m not happy about this issue, but so far failed to come up with a clean and fool-proof way of adding effects to signals...
In the following program I use effectful to print something on every iteration. However it only prints a few times (exact number of times varies from run to run) and then stops. The code uses the driveNetwork function from elerea-examples:
I'm using GHC 7.6.3 (Haskell Plattform) on Windows. Sometimes it takes a while until it stops printing, but it always stops at some point...