There’s always another way :).

If you’re reading one message at a time, you can keep a “countdown” value. The pseudo-code:

  1. Set “deadline” to “now + 10s”
  2. Wait for the next message (passing “deadline minus now” as your library-specific timeout)
  3. Handle the message (decrementing your 500)
  4. If “deadline < now”, loop back to step 2

Journalist, ex software engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store