refactored listing of indexes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-05-13 00:59:56 +03:00
parent 515863f94e
commit d960b02466

View File

@ -106,6 +106,24 @@ function(base, index_dir){
} }
// NOTE: this is similar to listIndexes(..) but will return a promise and
// skip all non-loadable nested indexes...
var getIndexes =
module.getIndexes =
function(base, index_dir, logger){
return new Promise(function(resolve, reject){
listIndexes(base, index_dir)
.on('error', function(err){
reject(err)
})
.on('end', function(paths){
// skip nested indexes...
resolve(skipNested(paths, index_dir, logger))
})
})
}
var listPreviews = var listPreviews =
module.listPreviews = module.listPreviews =
function(base){ function(base){
@ -336,17 +354,12 @@ function(path, index_dir, logger){
} else { } else {
var res = {} var res = {}
// XXX handle 'error' event... getIndexes(path, index_dir, logger)
listIndexes(path, index_dir) .catch(function(err){
// XXX handle errors...
.on('error', function(err){
logger && logger.emit('error', err) logger && logger.emit('error', err)
console.error(err) console.error(err)
}) })
.on('end', function(paths){ .then(function(paths){
// skip nested indexes...
paths = skipNested(paths, index_dir, logger)
// start loading... // start loading...
Promise.all(paths.map(function(p){ Promise.all(paths.map(function(p){
var path = pathlib.normalize(p +'/'+ index_dir) var path = pathlib.normalize(p +'/'+ index_dir)
@ -563,16 +576,12 @@ function(path, index_dir, from_date, logger){
} else { } else {
var res = {} var res = {}
listIndexes(path, index_dir) getIndexes(path, index_dir, logger)
// XXX handle errors... .catch(function(err){
.on('error', function(err){
logger && logger.emit('error', err) logger && logger.emit('error', err)
console.error(err) console.error(err)
}) })
.on('end', function(paths){ .then(function(paths){
// skip nested indexes...
paths = skipNested(paths, index_dir, logger)
// start loading... // start loading...
Promise.all(paths.map(function(p){ Promise.all(paths.map(function(p){
var path = pathlib.normalize(p +'/'+ index_dir) var path = pathlib.normalize(p +'/'+ index_dir)