Last active
August 5, 2016 22:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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