You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
construnTask=asyncfn=>{awaitfn();};constiters=3e6;asyncfunctionrunWithAwait(){letcounter=0;conststart=Date.now();for(letindex=0;index<iters;index++){await"any value :D or task";runTask(async()=>counter++);}return{ counter,time: (Date.now()-start)/1000};}asyncfunctionrunWithAwaitWithThen(){letcounter=0;conststart=Date.now();for(letindex=0;index<iters;index++){await"any value :D";runTask(async()=>{}).then(()=>counter++);}return{ counter,time: (Date.now()-start)/1000};}asyncfunctionrun(){letcounter=0;conststart=Date.now();for(letindex=0;index<iters;index++){runTask(async()=>counter++);}return{ counter,time: (Date.now()-start)/1000};}asyncfunctionrunWithThen(){letcounter=0;conststart=Date.now();for(letindex=0;index<iters;index++){runTask(async()=>{}).then(()=>counter++);}return{ counter,time: (Date.now()-start)/1000};}awaitrunWithAwait().then(res=>console.log("runWithAwait",res));awaitrunWithAwaitWithThen().then(res=>console.log("runWithAwaitWithThen",res));awaitrun().then(res=>console.log("run",res));awaitrunWithThen().then(res=>console.log("runWithThen",res));
How often does it reproduce? Is there a required condition?
Always if not awaited promise
What is the expected behavior? Why is that the expected behavior?
For example, you need to run asynchronous tasks with side effects that you don't need to wait for. Or the results go to the eventmeter, this can be useful for queues.
importEventEmitterfrom"node:events";constevents=newEventEmitter();constadd=asynctask=>{try{events.emit("success",awaittask());}catch(err){events.emit("err",{ err, task });}};functionaddTasks(){for(letindex=0;index<3e6;index++){//if you don't await it, you get bad performanceadd(async()=>{constisEven=index%2==0;if(isEven)throw"even";returnindex;});}}addTasks();/* for performance hack */// async function addTasksHack() {// for (let index = 0; index < 3e6; index++) {// await "";// add(async () => {// return index;// });// }// }// addTasksHack();
What do you see instead?
Not needed awaited result, with good performance
Additional information
No response
The text was updated successfully, but these errors were encountered:
Version
v22.11.0
Platform
Subsystem
No response
What steps will reproduce the bug?
result:
How often does it reproduce? Is there a required condition?
Always if not awaited promise
What is the expected behavior? Why is that the expected behavior?
For example, you need to run asynchronous tasks with side effects that you don't need to wait for. Or the results go to the eventmeter, this can be useful for queues.
What do you see instead?
Not needed awaited result, with good performance
Additional information
No response
The text was updated successfully, but these errors were encountered: