batch.processArray

use batch.processArray in notifications.push and moveRecentReplies
added notification tests
added test for moveRecentReplies
clear group cache if a group is deleted
This commit is contained in:
barisusakli
2016-10-11 16:06:42 +03:00
parent 035d59f52c
commit 038418bf87
7 changed files with 259 additions and 81 deletions

View File

@@ -16,7 +16,7 @@ var async = require('async'),
options = {};
}
callback = typeof callback === 'function' ? callback : function(){};
callback = typeof callback === 'function' ? callback : function() {};
options = options || {};
if (typeof process !== 'function') {
@@ -63,4 +63,52 @@ var async = require('async'),
);
};
Batch.processArray = function(array, process, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
callback = typeof callback === 'function' ? callback : function() {};
options = options || {};
if (!Array.isArray(array) || !array.length) {
return callback();
}
if (typeof process !== 'function') {
return callback(new Error('[[error:process-not-a-function]]'));
}
var batch = options.batch || DEFAULT_BATCH_SIZE;
var start = 0;
var done = false;
async.whilst(
function() {
return !done;
},
function(next) {
var currentBatch = array.slice(start, start + batch);
if (!currentBatch.length) {
done = true;
return next();
}
process(currentBatch, function(err) {
if (err) {
return next(err);
}
start = start + batch;
if (options.interval) {
setTimeout(next, options.interval);
} else {
next();
}
});
},
function(err) {
callback(err);
}
);
};
}(exports));