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

A fix for fs.WatchFile delays #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import path from 'path';

export default function (log) {
let defaultOptions = {
endOfLineChar: os.EOL
endOfLineChar: os.EOL,
fsPollInterval: 250

Choose a reason for hiding this comment

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

My personal preference would be to have the watch poll slightly less frequently. The data isn't super time-sensitive (though it would be nice to have sooner to better plan a next move) so I'd prefer not to have the additional overhead.

Maybe something like?:

Suggested change
fsPollInterval: 250
fsPollInterval: 1250

};
// Determine the default location of the config and log files.
if (/^win/.test(os.platform())) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export default class extends EventEmitter {
log.main('Log watcher started.');
// Begin watching the Hearthstone log file.
var fileSize = fs.statSync(self.options.logFile).size;
fs.watchFile(self.options.logFile, function (current, previous) {
if (current.mtime <= previous.mtime) { return; }
fs.watchFile(self.options.logFile, {interval: self.options.fsPollInterval}, function (current, previous) {
if (current.size <= previous.size) { return; }

// We're only going to read the portion of the file that we have not read so far.
var newFileSize = fs.statSync(self.options.logFile).size;
Expand Down