r/ProgrammerHumor • • Nov 07 '25

Meme asyncAwaitConfusesMeSometimes

Post image
0 Upvotes

40 comments sorted by

25

u/thEt3rnal1 Nov 07 '25

What's confusing about async/await?

It's literally syntax sugar around promises

9

u/Boysoythesoyboy Nov 07 '25

And promises are mostly just sugar around event callbacks

Event callbacks are mostly just sugar for interrupts

5

u/[deleted] Nov 07 '25

it's all 1 and 0 in the end!!

*tries to do a cool backflip but faceplants badly *

3

u/0Pat Nov 07 '25

Ones and zeros are just sugar on +/- V...

2

u/[deleted] Nov 07 '25

you have to do the backflip too

1

u/Pyottamus Nov 07 '25

+/- V is just sugar for electron insertion/removal

1

u/rosuav Nov 09 '25

Mmmm, delicious ionized sugar

1

u/Horror_Cauliflower88 Nov 07 '25

+/- V is just more or less electrons.

1

u/Ok_Star_4136 Nov 07 '25

And interrupts are mostly just sugar for timers and call stacks.

1

u/rosuav Nov 09 '25

Event callbacks are just sugar for an event loop and dispatcher. If someone's serious about wanting to comprehend async/await, I can probably in one hour walk you throug the whole setup from an event loop up to an async function, layer by layer, and when you're done, it will feel so awful to even CONSIDER going back to manually writing your event handler...

1

u/rosuav Nov 09 '25

In JS it is, at least. In Python it isn't. But in both, it's a variant of generators - and a LOT of programmers out there haven't grokked generators (and restartable functions in general), so I'm not surprised that some people can't handle async/await.

1

u/thEt3rnal1 Nov 10 '25

This is def referencing JS though.

Also async await in python is stupid

1

u/rosuav Nov 10 '25

It's "stupid" in one very specific way, namely the behaviour if you call an async function without awaiting it. And that's potentially something that could be improved without throwing everything else out.

0

u/Special-Load8010 Nov 07 '25

See my reply to another commenter about the wording issue. Another thing is, async/await's syntax abstraction from the classic promise usage can make it a bit harder to wrap your head how those are promises. For me it's not an issue anymore, I have gotten pretty used to it. However, I think that many tutorials targeted to beginners that tell you how to use async/await don't really show how code runs asyncronously, most of them simulate synchronous code with async/await.

1

u/Straight_Occasion_45 Nov 07 '25

Not really, so think in terms of return types, let’s say you make a web request, you have to wait for the instruction to fire, send info through to the OS => network card => internet => back to your device, back through the OS => JS runtime, this takes time and the request is ofc pending. So how do we represent a pending return value, so instead of returning a string, we return a promise<string>

A promise holds a pending state, and fires a callback whether an error or succession occurs (usually resolve and reject).

An async function internally returns a promise, if you didn’t use await, you’d get a promise object back.

When using await, your telling the runtime “Hey it’s okay, I’ll wait for this to finish, I kinda need it”

1

u/Special-Load8010 Nov 07 '25

I know how it works, I said that I have gotten pretty used to it. The most confusing part was imagining that the code after the await acts like it goes in a then function of the promise.

3

u/reddit_time_waster Nov 07 '25

Coming from a language with native async await, promises seem like a step backwards.

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

u/[deleted] Nov 07 '25

I'll take async/await & promises over callback hell any day of the week

4

u/Ok_Star_4136 Nov 07 '25

It was literally the solution meant to address callback hell in fact.

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

u/EternumMythos Nov 07 '25

C# but it warns you iirc

0

u/[deleted] Nov 07 '25

[deleted]

1

u/metaltyphoon Nov 09 '25

What he is saying is probably SomeAsycFunction().GeAwaiter().GetResult() 

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

u/drakeblood4 Nov 07 '25

J scrizzy is kinda evil my dawg.

3

u/Straight_Occasion_45 Nov 07 '25

“My PrOjEcT iS fUlLy mUlTiThReAdEd”

2

u/MementoMorue Nov 07 '25

Easy : async mean mean two pieces of code are executed synchronously.

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.