Skip to content

Instantly share code, notes, and snippets.

@drodsou
Last active August 5, 2016 22:27
Show Gist options
  • Save drodsou/59cf4d4f63c29d734d3fa4c145ac163b to your computer and use it in GitHub Desktop.
Save drodsou/59cf4d4f63c29d734d3fa4c145ac163b to your computer and use it in GitHub Desktop.
Like fs.watch but with a timeout to not trigger n times each change
// tames fs.watch to not trigger n times each
// fn (event, filename)
// --------------------------------
function watchFileOrFolder(fileOrFolder, timeout, fn) {
let paused=false
fs.watch(fileOrFolder, {persistent: true, recursive : true}, function (event, fileName) {
if (!paused) {
fn(event,fileName)
paused=true
setTimeout(()=>paused=false,timeout)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment