Created
October 3, 2012 15:30
-
-
Save dallonf/3827586 to your computer and use it in GitHub Desktop.
AwaitScript concept
This file contains hidden or 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
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