Below is a minimized code snippet which causes the async warning in VS code (most recent version 1.70.). It is part of a load balancing algorithm which is to execute asynchronous tasks.
When the generateTask function returns a promise directly the warning disappears. When the Promise.all promise is returned I get the warning "await has no effect" (w1). Despite the warning the code behaves as wanted and waits until tasks.reduce is ready with the tasks array (which has just one task here of course for testing).
The function of the code is ok. So I am wondering whether that is a problem of the Javascript parser of VS Code. When I put the same code snippet into the script part of an HTML file VS Code does not produce the warning. As well if I put it to a ts Typescript file.
Any idea to that would be appreciated
// nodejs 16 test function. VSCode 1.70.1 IDE
async function jobExecutorMinified() {
const generateTask = () => {
return () => {
const p = new Promise(resolve => {
setTimeout(() => {
resolve();
}, 5000);
});
// returning the promise of Promise.all -> warning w1
return Promise.all([p]);
// returning the promise directly -> no warnings
// return p;
}
}
const tasks = [generateTask()];
/*w1*/await tasks.reduce((prevTask, currTask) => {
return prevTask.then(() => {
return currTask();
});
}, Promise.resolve());
console.log('task chunking is ready');
}
jobExecutorMinified().then(() => {
console.log('job executor minified returned');
});