Re:Breaking Up with Long Tasks or: how I learned to group lo...
by leeoniya on Monday January 06, 2025 @09:43AM
(#42610937)
> A lot of junior devs I've worked with don't understand that putting `async` in front of a function doesn't actually make it asynchronous.
of course it does. annotating any function with async makes it implicitly return a Promise, which fundamentally changes how all callers have to use it (and their caller's callers, etc.). you can't "just" make a function async and change nothing about how it was used previously.
https://jsfiddle.net/om3tj2rd/
async function foo() {
return 2;
}
console.log(foo());
this
Re:Breaking Up with Long Tasks or: how I learned to group lo...
by leeoniya on Tuesday January 07, 2025 @02:51PM
(#42626601)
> of course it does.
i should clarify a bit, that this can still freeze your UI if foo() is expensive, since the microtask still runs on the same event loop. my point is that you cannot always throw async in front of a function and not change any other code.
A lot of junior devs I've worked with don't understand that putting `async` in front of a function doesn't actually make it asynchronous.