Use whilst instead of forever

this gets rid of the Error object
This commit is contained in:
Girish Ramakrishnan
2019-12-04 11:17:42 -08:00
parent 30eccfb54b
commit 85e17b570b
3 changed files with 24 additions and 26 deletions

View File

@@ -115,27 +115,25 @@ function listDir(apiConfig, backupFilePath, batchSize, iteratorCallback, callbac
query.maxResults = batchSize;
}
async.forever(function listAndDownload(foreverCallback) {
bucket.getFiles(query, function (error, files, nextQuery) {
if (error) return foreverCallback(error);
let done = false;
if (files.length === 0) return foreverCallback(new Error('Done'));
async.whilst(() => !done, function listAndDownload(whilstCallback) {
bucket.getFiles(query, function (error, files, nextQuery) {
if (error) return whilstCallback(error);
if (files.length === 0) { done = true; return whilstCallback(); }
const entries = files.map(function (f) { return { fullPath: f.name }; });
iteratorCallback(entries, function (error) {
if (error) return foreverCallback(error);
if (!nextQuery) return foreverCallback(new Error('Done'));
if (error) return whilstCallback(error);
if (!nextQuery) { done = true; return whilstCallback(); }
query = nextQuery;
foreverCallback();
whilstCallback();
});
});
}, function (error) {
if (error.message === 'Done') return callback(null);
callback(error);
});
}, callback);
}
function copy(apiConfig, oldFilePath, newFilePath) {