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

refactor(listener): change condition "running" to be based on if the channel is open or not #76

Closed
wants to merge 1 commit into from

Conversation

hasezoey
Copy link
Contributor

@hasezoey hasezoey commented May 4, 2024

Description

This PR refactors the event listener to not have a extra running arc-rwlock-bool and instead completely relies on whether the channel is open or not, this reduces the amount of locking that is necessary and reduces the amount of things that need to be checked.

In addition to verify it is completely working, a new test has been added that tests the more public (pub) api by actually starting and checking the loop.

Type of change

Please select relevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves performance, style or non-behavior changing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the contribution guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I formatted the code with cargo fmt
  • I checked my code using cargo clippy and reports no warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have introduced no new C-bindings
  • The changes I've made are Windows, MacOS, UNIX, Linux compatible (or I've handled them using cfg target_os)
  • I increased or maintained the code coverage for the project, compared to the previous commit

…channel is open or not

instead of a arc-rwlock-bool in addition to "channel is open"
@hasezoey hasezoey marked this pull request as draft May 4, 2024 15:17
@hasezoey
Copy link
Contributor Author

hasezoey commented May 4, 2024

Converted this back to a draft because the current termion poll implementation actually blocks until there is a event, which in tests there never is.
This is a problem because with this refactor the thread actually start and polls faster than the first thread which immediately stopped the input thread and so on current main (40ee05c) never actually polls termion.

/// This function mustn't be blocking, and will be called within the configured interval of the event listener.

this also means to my understanding anyone actually using backend termion and wants to use more than that input port is basically unable to

PS: i am unable to stop the CI tests which now run indefinitely (until killed because of long timeout)

@veeso
Copy link
Owner

veeso commented Oct 13, 2024

Mhm, actually using a AtomicBool instead of a RwLock was enough.

@veeso veeso closed this Oct 13, 2024
@hasezoey
Copy link
Contributor Author

Mhm, actually using a AtomicBool instead of a RwLock was enough.

it is definitely better than a rwlock, but i still think the property running could be eliminated by just checking if the channel is open or not (and like in this pr wrap it in option to drop it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants