-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register handlers on actuate and unregister them on pause #173
base: master
Are you sure you want to change the base?
Conversation
8cd04b6
to
d06c496
Compare
Is there anything I can do to help move this along? This PR has been sitting here untouched for quite a while now. |
Unfortunately I don't think |
@Kritzefitz Are you still interested in getting this one through? |
I've read over the implementation, and I think it looks 👍 overall, but I did find the encoding of the state of the network rather confusing to puzzle through. I have a general suggestion for a refactoring that I think could improve things. This patch encodes the state of the event network (actuated/paused), the "register" actions we've accumulated (either while actuated or paused), and the "unregister" actions to call when paused all in the same "anonymous" data type: ([IO (IO ())], Maybe [IO ()]) I suggest perhaps writing down a dedicated data type, such as: data NetworkState
= NetworkState
{ actuated :: Bool
, registerHandlers :: [IO (IO ())]
, unregisterHandlers :: [IO ()]
} Second, I think everywhere you've written And finally, since we |
Generally I'd be willing to make those adjustment. The more interesting question is when I will have the time to do it, as I can't really make a commitment in that regard right now. |
d06c496
to
ccddec5
Compare
I just pushed a new commit with your suggestions applied. As you suggested, the |
ccddec5
to
0880f7e
Compare
if actuated state | ||
then pure state | ||
else (\unregs -> state { actuated = True, unregisterHandlers = unregs }) | ||
-- We intentionally use foldr here to ensure that the register |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment mentions foldr
, but I don't see one :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, good point. I originally used foldr
here, but later thought that it is less efficient than using reverse
two times.
I just updated the comment, so it should be correct now.
0880f7e
to
e7a9e5f
Compare
LGTM! Thanks! =) Two last things -
|
Thanks a lot for your work! However, I actually do want to look over it. The issue is that even though the code looks fine, I'm not entirely certain that it does the right thing when new inputs are added in the context of say, |
e7a9e5f
to
4b15fd5
Compare
Done
I couldn't get reactive-banana-wx to compile, because wx doesn't seem to compile with newer GHC versions, while old enough GHC versions panic when used on my current setup. However, I tried my modified version using this commit from my own application. It does use I'll try to write down my theoretical thoughts about this: There is added potential for deadlocks, because the network state
I'm not sure if there are use cases for calling If we want to support those cases, we probably need much more explicit locking for the network state, such as: data NetworkState
= Actuated { registerHandlers :: [IO (IO ())], unregisterHandlers [IO ()] }
| Actuating
| PausedWhileActuating
| Paused { registerHandlers :: [IO (IO ())] }
| Pausing
| ActuatedWhilePausing
| Registering
| PausedWhileRegistering The state would then have to be kept in a
With the rules above, |
This should fix the issue that handlers registered by
fromAddHandler
were not unregistered bypause
. It also brings the implementation in line with the documentation, which says that input handlers will only be registered once actuate is called.Closes #73