Skip to content
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

EventListener::run_handler now takes an Arc to the handler instead of moving it #9

Merged
merged 2 commits into from
Jun 17, 2022

Commits on Jun 17, 2022

  1. EventListener::run_handler now takes an Arc to the handler instead of…

    … moving it
    
    This is convenient when the handler stores, or refers to outside state. By taking an atomic reference, we can simply clone the reference counting ptr and keep it around to inspect the state of the handler (assuming the handler allows inspection of its contents).
    
    The cost compared to just moving the handler is negligible compared to the expected cost of the running lifetime of the handler.
    
    Unfortunately, since thread::spawn takes an F: 'static, we can't just take the handler by reference. We may be able to use scoped threads and put the scope in the EventListener::FinishProcessingHandle, but doing so would require doing acrobatics with lifetimes beyond the added value, over the little added cost of introducing the Arc.
    
    A bigger disadvantage of taking an Arc is that the Arc will be present in the EventListener::run_handler API.
    
    Why Arc over Rc? It is expected that since the handler must run in some place where it doesn't block the main loop, some form of concurrency will be exhibited. As such, we would require the atomicity of the Arc.
    foresterre committed Jun 17, 2022
    Configuration menu
    Copy the full SHA
    fa10eef View commit details
    Browse the repository at this point in the history
  2. Update changelog

    foresterre committed Jun 17, 2022
    Configuration menu
    Copy the full SHA
    1d42a4e View commit details
    Browse the repository at this point in the history