Skip to content

Conversation

@IvanSanchez
Copy link
Member

Fixes gobblejs/gobble#110

The root cause was my text editor (kate): when making modifications to a file, it moves (renames) the existing file (gobblefile.js) into a backup file (gobblefile.js~), and re-creates a file with the original name. Pathwatcher interprets that as deleting the file.


if ( type === 'delete' ) {
logger.info({ code: 'GOBBLEFILE_DELETED' });
return setTimeout( watch, 2000 );
Copy link
Contributor

Choose a reason for hiding this comment

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

what about a setInterval that gets cancelled once the file exists again? Or, equivalently...

function checkGobbleFileExists () {
  fs.exists( gobblefile, exists => exists ? restart() : setTimeout( checkGobbleFileExists, 100 ) );
}

// ...
if ( type === 'delete' ) {
  logger.info({ code: 'GOBBLEFILE_DELETED' });
  return setTimeout( checkGobbleFileExists, 100 );
}

That way you don't have to wait 2 seconds each time the editor saves. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have a strong opinion about this particular bit. Waiting 2 seconds works reliably for my use case, but I can see the appeal of checking for the gobblefile in a loop.

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.

3 participants