Nodejs RangeError Maximum Call Stack Exceeded

There are more than 2000 objects in the array of strings that need to be processed, but received an error. Maximum call stack exceeded. The callback function manages the database. I tried to use

Settimeout

which works but slow execution. Is there any other way to fix it.

var updateRowsStatus = function (req, rows, next) { if (rows.length == 0) { return next(); } var batchRows = rows.splice(0, 20); var count = 0; batchRows.forEach(function (row) { // other function updateSubEntity(req, row, 'rows', function (err, response) { if (err)throw err; if (++count == batchRows.length) { updateRowsStatus(req, rows, next); } }); }); }; 
+5
source share
1 answer

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(); } }); }); } 
0
source

All Articles