I want to process the operation in parallel as soon as files are being received at server in non-blocking way.
I have tried this:
(async () => {
await io.setMaxListeners(0)
await io.on('connection', async (client) => {
await fse.copy(__dirname + /files/ + event.file.id, `${fileinfo}${meta.name}`);
console.log("File copied");
const thumbDirExists = await fse.pathExists(thumbDir);
thumbDirExists === false && await fse.ensureDir(thumbDir)
console.log("Thumb Dir created");
let readyFile = `${fileinfo}${meta.name}`;
let resizeFile = `${thumbDir}${meta.name}`;
await createThumb(readyFile, resizeFile).then(async imageBuffer => {
console.log("Resized!")
await client.emit('image', { image: true, buffer: imageBuffer.toString('base64') });
console.log("Image sent")
})
})
})();
Expected result:
File copied
Thumb Dir created
Resized
Image sent
File copied
Thumb Dir created
Resized
Image sent
File copied
Thumb Dir created
Resized
Image sent
Actual result:
File copied
File copied
File copied
Thumb Dir created
Thumb Dir created
Thumb Dir created
Resized
Image sent
Resized
Image sent
Resized
Image sent
It seems like the actual result is first copying all the files in blocking way then creating thumb directory in blocking way.
Edit: The duplicate answer does not address my problem. My question is about async/await operation in parallel and non-blocking way. I don't want to use any third party library like promisfy.