Someone sent this solution but deleted. So I send his decision again. Thanks to him.
var count = 0; var length = rows.length; while (rows.length > 0) { console.log('rows -', rows.length); var batchRows = rows.splice(0, 20); batchRows.forEach(function (row) { updateSubEntity(req, row, 'rows', function (err, response) { if (err)throw err; if (++count == length) { return next(); } }); }); }
source share