Maven (famous)@lemmy.world to Programmer Humor@lemmy.ml · 11 months agoSTOP DOING ASYNClemmy.worldimagemessage-square90fedilinkarrow-up1706arrow-down139
arrow-up1667arrow-down1imageSTOP DOING ASYNClemmy.worldMaven (famous)@lemmy.world to Programmer Humor@lemmy.ml · 11 months agomessage-square90fedilink
minus-squareBene7rddso@feddit.delinkfedilinkarrow-up1·11 months agoIf you need to get multiple pieces of data for one request Async is great, but why would you work on different requests in the same thread? Why slow down one request because the other needs a bunch of computation?
minus-squareLmaydev@programming.devlinkfedilinkarrow-up3·11 months agoYou aren’t slowing down anything. If you didn’t use async that thread would be blocked. You’d need a thread per request even though they are sat doing nothing while waiting for responses. Instead when you hit an await that thread is freed for other work and when the wait is over the rest of the code is scheduled to run.
If you need to get multiple pieces of data for one request Async is great, but why would you work on different requests in the same thread? Why slow down one request because the other needs a bunch of computation?
You aren’t slowing down anything. If you didn’t use async that thread would be blocked.
You’d need a thread per request even though they are sat doing nothing while waiting for responses.
Instead when you hit an await that thread is freed for other work and when the wait is over the rest of the code is scheduled to run.