Time slots app prototype
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
918 B

const { readdir } = require("../compat/fs");
const { init, walkSingleDir, readdirOpts } = require("./shared");
function promise(dir, options) {
return new Promise((resolve, reject) => {
callback(dir, options, (err, output) => {
if (err) return reject(err);
resolve(output);
});
});
}
function callback(dirPath, options, callback) {
const { state, callbackInvoker, dir } = init(dirPath, options, callback);
walk(state, dir, options.maxDepth, callbackInvoker);
}
function walk(state, dir, currentDepth, callback) {
if (currentDepth < 0) {
--state.queue;
return;
}
readdir(dir, readdirOpts, function(error, dirents) {
if (error) {
--state.queue;
callback(error, state);
return;
}
walkSingleDir(walk, state, dir, dirents, currentDepth, callback);
if (--state.queue < 0) callback(null, state);
});
}
module.exports = { promise, callback };