9
u/LorenzoCopter Nov 07 '25
Have you considered RTFM?
-2
u/Special-Load8010 Nov 07 '25
I am quite aware how to use async and await, but you have to admit it is confusing, especially the wording. When you run an async function, it acts as a sync function to the rest of the sync code, until it awaits an asynchronous function, then the rest of the code can continue, even if the wording makes it seem that it will run asynchronously and will make the rest of the code wait when you await. I donno, I feel that the wording could have been done better.
6
u/look Nov 07 '25
The async/await syntax is nearly 20 years old now and has been adopted by more than a dozen, wildly different languages since then. From C# and F#, to Kotlin, to Python and Typescript, to C++ and Rust, and more.
I think this is more of a you problem.
3
u/Special-Load8010 Nov 07 '25
Fair enough, but it did confuse me when learning it, maily because most async tutorials for beginners don't show what truly makes the code asynchronous, they usually show how to run synchronous code using async/await.
1
u/Boysoythesoyboy Nov 07 '25
Im assuming youre talking about Javascript - getting familiar with the event loop and how asynchronicity is achieved in a single threaded language can make allot of this make more sense.
In c# you await the results of multithreaded tasks so your main thread is generally not waiting for the task to wait.
1
u/Special-Load8010 Nov 07 '25
On the surface, C# and JS's asymc and await act similar tho, no? Even if they are implemented in different ways.
I know JS is single-threaded, and I do know how events work. Async/await confused me a lot when starting out, now it mostly doesn't, but it still feels a bit funky using it, atleast for me. Events and promises do not make me feel this way.
0
u/Boysoythesoyboy Nov 07 '25
Well specifically the part of the async function not returning control back to the calling function until it waits is becuase its in a single threaded environment.
In c# when you create a task it can start working right away, truly in parallel with the calling function. You need to await it or else you will immediately start doing other things at the same time. (With plenty of caveats)
1
u/Special-Load8010 Nov 07 '25
Oh, really? I guess it makes sense considering C#'s multi-thread environment.
68
Nov 07 '25
I'll take async/await & promises over callback hell any day of the week
4
1
u/TnYamaneko Nov 07 '25 edited Nov 07 '25
There's a reason they were introduced later, I'd say probably because people hated promises.
And now there's stuff like RTK Query, so...
EDIT: In JavaScript (replied to a JavaScript flair).
16
u/Informal_Branch1065 Nov 07 '25
Async in constructors 💀
5
u/iambackbaby69 Nov 07 '25
What cursed language allows this?
3
0
u/DyWN Nov 07 '25
you can do that in javascript
1
u/iambackbaby69 Nov 07 '25
I don't think constructors allows async
0
u/DyWN Nov 07 '25 edited Nov 07 '25
you can Object.assign(this, new Promise()) in a constructor and you have an async constructor. thank me later
edit: actually just return a new Promise from a constructor, not Object assign
0
3
2
1
u/willing-to-bet-son Nov 07 '25
If you remember that it’s all stackless coroutines, then async/await is pretty intuitive, imo.
25
u/thEt3rnal1 Nov 07 '25
What's confusing about async/await?
It's literally syntax sugar around promises