The question is, when are you done? If you don't stop waiting because you know you have enough messages, you must wait for a timeout.

The alternative would be to do a loop and check each message as it comes in to see if it fulfills the test... would you find that better? I can do that, and that would eliminate the counting (which I completely agree is brittle at best).