0
I have the following code segment:
generateEpisode(result,programId).then((arrayBlocks) =>{
const promises = []
arrayBlocks.map((file,index) =>{
promises.push(normalizeFile(file,index))
});
Promise.all(promises).then((finalFiles) =>{
res.render("user/episodes/reviewEpisode",{script: finalFiles});
}).catch((error) =>{
req.flash("error_msg", error.message);
res.redirect('/user/episodios');
});
}).catch((error) =>{
req.flash("error_msg", error.message);
res.redirect('/user/episodios');
});
In which the function normalizeFiles()
creates a new file for each file arrayBlocks
, but the files are correct, but after solving them and generating the files, they begin to solve again even though they have already solved them, turning an infinite loop and never rendering the view.
function normalizeFiles
:
async function normalizeFile (file,index){
return new Promise((resolve,reject) =>{
let newFilename = "newFIle"+(index+1)+'-'+Date.now()+".wav";
normalize({
input: './public/uploads/'+file,
output: './public/uploads/result/'+newFilename,
loudness: {
normalization: 'ebuR128',
target:
{
input_i: -23,
input_lra: 7.0,
input_tp: -2.0
}
},
}).then(() =>{
console.log('created the file!');
resolve(newFilename);
}).catch((error) =>{
console.log('error!')
reject(error);
});
});
}
You can show the function
normalizeFile
?– Sergio
I edited the post and added the normalizeFile
– tanji
Adds
return
beforePromise.all
insidegenerateEpisode(...).then(
– Sergio
You can simplify by writing only
const promises = arrayBlocks.map(normalizeFile); return Promise.all(promises);
– Sergio
Still it continues in loop, example, I put to print the generated files and the map files (in this case the Locks arrayBlocks had 2 files). outworking:
[ Promise { <pending> }, Promise { <pending> } ]
[ 'newFile 1-1568378345251.wav', 'newFile 2-1568378345258.wav' ]
[ Promise { <pending> }, Promise { <pending> } ]
– tanji
But you know if he’s going to the
.catch(
? and which one of them?– Sergio
It does not stop at any catch, the
console.log(finalFiles)
, ta inside the last.then(
hence it prints the two generated files:[ 'newFile 1-1568378345251.wav', 'newFile 2-1568378345258.wav' ]
and then re-print the files and generate again and again, but it never renders the view and loops all the files– tanji