I am currently working on creating a new File object from blob data within a .then structure. However, I have encountered an issue where the second .then function runs before the first one finishes, resulting in the file object not being fully filled yet.
Is this normal behavior? Should I consider making the first .then function an async function to ensure that the second one is only called after the file object has been properly populated?
let output = {file: {}, file_infos: {}},
image = FileAPI.Image(src_file);
await Promise.all(Object.keys(parameters).map(async (parameter_name) => {
try {
image = await FileMethods[parameter_name](image, parameters[parameter_name]);
return image;
}
catch(err) {
console.log(err);
};
}))
.then((output_image) => {
output_image[0].toBlob((blob) => {
output.file = new File([blob], src_file.name); // This needs to be completed before moving to step 2
console.log('step1');
});
})
.then(() => {
console.log('step2');
FileAPI.getInfo(output.file, (err/**String*/, infos/**Object*/) => {
if( !err ){
output.file_infos = infos;
} else {
console.log("This error occurred because output.file was not fully filled yet");
}
})
});
// console.log(output);
return output;
The console output displays:
step2
This error occurred because output.file was not fully filled yet
step1
Thank you for your assistance :)