Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests run twice on windows

2 participants