r/learnprogramming • • Sep 29 '26

Struggling with async programming & concurrency

I come from a pure hardware and embedded background where code runs sequentially, so writing high level async software has never been my strength.

I really can't wrap my head around async/await, event loops and how it is handled deterministically . In a current project when the team said we needed to make our pipeline non-blocking with async streams, to be honest I just vibe coded the hell of my tickets in panic and tried later on to figure it out, partially..

I have a deployment deadline in a week and I need to be able to explain the mechanism I helped ”build“, any easy to follow tutorials or leetcodes would be highly appreciated

33 Upvotes

25 comments sorted by

View all comments

Show parent comment

8

u/[deleted] Sep 29 '26

[removed] — view removed comment

1

u/sixtyhurtz Sep 29 '26

In my first year at uni in our introduction to programming classes, they had us doing stuff with Arduino. We had a coursework assignment to build something with it. The project I ended up doing was making a stepper motor oscillate, ping an ultrasonic sensor, and make a speaker beep if something was in range. Basically a toy radar.

I thought the whole business of procedurally looping over everything was frightfully dull, so I decided to make it a bit more interesting. I made my main loop iterate over an array of function objects. I think I had enough space for maybe 4, because that was the maximum number of things I could do at once. Each function object had some metadata associated with it such as when it next expected to run, so the loop scheduler could just skip it if it wasn't needed. Some of them would attach or remove functions to the loop (e.g. the beeping).

When I wrote this, I had no idea what an async event loop was. Despite that, I made it happen on an AVR with 2kb of memory!

So again, u/ShronkPonk - you're probably already doing async things in your firmware. It's just a model of concurrency.