Closed hanshoglund closed 8 years ago
This looks like an issue with garbage collection to me. (Also, your code does not compile as rectHandler
is not in scope). As the documentation for exportHandler
says:
WARNING: The event handler will be garbage collected unless you keep a reference to it on the Haskell side! Registering it with a JavaScript function will generally not keep it alive.
You need to use addReachable
to connect the result of exportHandler
to the root
of the window if you want to keep the RemotePtr alive after the argument to serve
has finished.
Thanks Heinrich, I'll give it a go (rectHandler
should have been handler
btw – bad refactoring before posting).
I'm using Foreign.JavaScript to communicate between some custom JS GUI stuff and a Haskell backend. The JS GUI need to send values to the backend in response to certain events, so I am using
exportHandler
to pass a HS handler to the JS side. However this callback failed to execute until I came up with the idea of letting HS call into JS occasionally in a separate thread as per below – note that I'm not doing anything with the callback in the dummy function.Is this expected, and if so, what is the conditions in which JS may call back into HS?