I’m writing a background program that waits for tasks, then does work. (Specifically it’s a golang program that reads tasks from a redis queue.) When there are no tasks (queue is empty), I’ve got this running a for true {...}
loop that repeatedly checks the queue. Is this wasting CPU cycles, or is it unavoidable? I think there are ways to push messages to a program, but I think on some level those mechanisms work by repeatedly checking anyway. Because the program is only doing this one thing, I think I can rely on the OS to handle multiprocessing. But still it feels odd to run a program around the clock to respond to occasional work. What is best practice here?
Thank you!