Rebuild --watch
event loop to simplify; fix concurrency issues
#40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before, the watcher event loop relied on multiple threads and raised an exception to interrupt the main thread whenever a file system change event happened. This was messy and resulted in zombie processes and other weird behavior when a file system change was detected in the middle of running tests.
This commit refactors the implementation to use a new
EventQueue
class. It leverages the buffering inherent in stdin, plus uses a thread-safe queue for placing file system change events, and then "pops" the next of these in each iteration of the event loop.To avoid starting a separate thread for reading key presses, the "pop" operation takes turns polling stdin (peeking at its buffer to see if a key press happened) and blocking for short period waiting for file system events.
The result is cleaner, easier to test, and not prone to the zombie process bug.