10
C0D4
2y

Forgive me devLords, for I have sinned.

Today, I took while() loop and made it true, it was a dirty ordeal, however it's not entirely my fault, you see the api I called doesn't have a webhook of any kind and doesn't return results in real time either, you have to poll for them..... so here I am writing while(true){} to poll for results that could take seconds or even hours to finish.

😟

Comments
  • 2
    Sounds like a prayer tho
  • 4
    @johnmelodyme I was praying there was a better way, but nope 🥲

    You just keep making a call to see if it's done yet.
  • 1
  • 1
    So what? Not an unusual thing
  • 3
    Yeah, not unusual. It's a busy waiting loop. I hope you at least added some Sleeps to it, so it actually gives the CPU some rest. Obviously best way would be to use synchronization primitives, but if that's not available then its ok to use busy waiting
  • 1
    How to make algorithms faster in c++:

    While true.

    This guy knows his stuff:
    https://youtube.com/watch/...
  • 0
    throw it into a thread wrapping in a try catch and forget it exists #yolo
  • 1
    Even almighty AWS sins.

    Many of their async API operations only offer polling to check results.

    Many do not notice because the CLI/SDKs hide it from you...
  • 0
    Dont our phones check for google notifs every x seconds aswell
  • 1
    @joewilliams007 IIRC they do a long poll, so a request that only times out after a few minutes, get an early response if there's anything to notify
  • 0
    @atheist

    I dont remember how exactly it looked like but in general, phone opens up connection and lets it sit idle
Add Comment