Skip to content

Add file throttling #34

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

Merged
merged 4 commits into from
Jan 27, 2020
Merged

Conversation

axelson
Copy link
Contributor

@axelson axelson commented Oct 4, 2019

Adds a simple throttle timer to group changes together and avoid tests running multiple times due to multiple file events being emitted by one editor save operation.

Fixes #9
Code inspired by #21
Code based on #33 (to keep the formatting changes separate)

GenServer.cast(Controller, {:file_changed, file_type(path), path})
%State{file_events: file_events, throttle_timer: throttle_timer} = state

unless throttle_timer do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, maybe I'm missing something, but does this ever get set to anything other than nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that definitely looks like an oversight. Will fix it up in a bit 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, code is updated to actually set and clear the timer.

@axelson axelson force-pushed the add-file-throttling branch from d70ffcf to 5bfced7 Compare October 11, 2019 07:20
Ideally we could make use of `Kernel.ParallelCompiler.compile/2` but that would
require larger changes to code.
@axelson axelson force-pushed the add-file-throttling branch from 5bfced7 to da0100f Compare October 11, 2019 07:23
%State{file_events: file_events, throttle_timer: throttle_timer} = state

throttle_timer =
unless throttle_timer do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this set the throttle timer to nil the second time the file event is run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again you are completely correct. Sorry for the back and forth but I have updated the code to fix this issue.

To help prevent us (well me) from making issues like this in the future it would be nice to add some tests. As part of this change I did write a test, but in my opinion it is too tied to the current implementation (liberal use of :sys.get_state) to be a worthwhile test going forward. In order to better test the module it is necessary to change the implementation slightly to facilitate testing, specifically I think the start_link function could take an optional argument that would store both the file_changed recipient (defaulting to Cortex.Controller) and the throttle_timeout (defaulting to 100). I'll just put that up as a separate PR.

@axelson axelson force-pushed the add-file-throttling branch from 02901d8 to 675dd77 Compare October 12, 2019 15:35
@axelson axelson mentioned this pull request Oct 14, 2019
@axelson
Copy link
Contributor Author

axelson commented Jan 7, 2020

@glittershark can you take another look?

@glittershark glittershark merged commit 8fdd6b9 into urbint:master Jan 27, 2020
@axelson axelson deleted the add-file-throttling branch January 27, 2020 17:29
@axelson
Copy link
Contributor Author

axelson commented Jan 27, 2020

Thanks!

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.

Tests run twice on windows
2 participants