using async in batch

removed unused code in debug
This commit is contained in:
Baris Usakli
2017-07-06 12:07:56 -04:00
parent 922790cc40
commit d469f53eba
3 changed files with 50 additions and 110 deletions

View File

@@ -49,18 +49,20 @@ exports.processSortedSet = function (setKey, process, options, callback) {
return !done;
},
function (next) {
db.getSortedSetRange(setKey, start, stop, function (err, ids) {
if (err) {
return next(err);
}
if (!ids.length || options.doneIf(start, stop, ids)) {
done = true;
return next();
}
process(ids, function (err) {
if (err) {
return next(err);
async.waterfall([
function (next) {
db.getSortedSetRange(setKey, start, stop, next);
},
function (ids, _next) {
if (!ids.length || options.doneIf(start, stop, ids)) {
done = true;
return next();
}
process(ids, function (err) {
_next(err);
});
},
function (next) {
start += utils.isNumber(options.alwaysStartAt) ? options.alwaysStartAt : options.batch + 1;
stop = start + options.batch;
@@ -69,8 +71,8 @@ exports.processSortedSet = function (setKey, process, options, callback) {
} else {
next();
}
});
});
},
], next);
},
callback
);
@@ -106,17 +108,21 @@ exports.processArray = function (array, process, options, callback) {
done = true;
return next();
}
process(currentBatch, function (err) {
if (err) {
return next(err);
}
start += batch;
if (options.interval) {
setTimeout(next, options.interval);
} else {
next();
}
});
async.waterfall([
function (next) {
process(currentBatch, function (err) {
next(err);
});
},
function (next) {
start += batch;
if (options.interval) {
setTimeout(next, options.interval);
} else {
next();
}
},
], next);
},
function (err) {
callback(err);