this post was submitted on 28 Jan 2024
676 points (94.8% liked)
Programmer Humor
32380 readers
1347 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Yeah, that's a big simplification and I get it. But the
async
syntax itself syntax "sugar" for Promises. It's not like C# or Java/Android where it will spawn a thread. If you take a JSON of 1000 rows and attach a promise/await to each of them, you won't hit the next event loop until they all run to completion.It's a common misconception that asynchronous means "run in background". It doesn't. It means run at end of current call stack.
And you STILL have to call
setTimeout
in yourasync
executions or else you will stall your UI.Again
async
is NOT background. It's run later.async
wrapsPromise
which wrapsqueueMicrotask
.Here is a stack overflow that explains it more in detail.
I’m well aware how async works in the single threaded js environment. All code blocks the main thread! Calling await on an async operation yields back.
You’re right, async is commonly mixed up with multi-threaded. And in fact in many languages the two things work hand in hand. I’m very aware of how it works in JavaScript.
We are agreeing. Don’t need more info.