I am getting Error: EMFILE: too many open files, open 'slices/224.png' when trying to use node-resemble.js within 2 foreach loops and comparing images from one folder to another folders. Is there a fix for the issue?
var filesArr = out.split('\n');
filesArr.splice(-1,1);
var finalArr = [];
filesArr.forEach( function(file, index) {
liblist.forEach(function(libFile, libIndex) {
var p = new Promise(( resolve ) => {
resemble( path.join( dirname, file ) ).compareTo( path.join( libdir, libFile ) ).ignoreColors().onComplete(function(data) {
if ( Number( data.misMatchPercentage ) <= 0.01 ) {
//console.log( data );
finalArr.push( libFile.charAt(0) );
fs.unlinkSync( path.join( dirname, file ), err => {
if (err) throw error;
});
if ( index === filesArr.length - 1 ) {
//return resolve( finalArr )
}
} else {
//console.log( 'No match' );
}
});
});
p.then(function(finalArr){
console.log(finalArr.join(""))
process.exit();
});
});
});
If I remove the promise call then the script executes without it fine. However, for long number of characters it fails and generates the aforementioned error.
I am getting Error: EMFILE: too many open files, open 'slices/224.png' when trying to use node-resemble.js within 2 foreach loops and comparing images from one folder to another folders. Is there a fix for the issue?
Complete error is...
If I remove the promise call then the script executes without it fine. However, for long number of characters it fails and generates the aforementioned error.