Skip to content

Instantly share code, notes, and snippets.

@dallonf
Created October 3, 2012 15:30
Show Gist options
  • Save dallonf/3827586 to your computer and use it in GitHub Desktop.
Save dallonf/3827586 to your computer and use it in GitHub Desktop.
AwaitScript concept
require 'fs';
require 'path';
// Check recursively if any files from this directory have been modified since a certain date
async function isRecentlyModified(dir, since) {
var files;
try {
files = await fs.readdir(dir);
} catch (ex) {
console.error("Warning: " + dir + " does not exist")
return;
}
await parallel foreach (var f in files) { // Not quite liking this syntax
var fullPath = path.join(dir, f);
var stat = await fs.stat(fullPath);
if (stat.isDirectory()) {
if (await isRecentlyModified(fullPath, since)) {
return true;
}
} else if (stat.isFile() && stat.mtime > since) {
return true;
}
}
return false;
}
var lastCheck = 0;
setInterval(async function() {
if (await isRecentlyModified('./test', lastCheck)) {
console.log("Folder has been modified");
} else {
console.log("Folder is the same");
}
lastCheck = new Date().getTime();
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment