and frankly unreliable because you can get stuck here!
If there is no serial data, there is nothing to do, so the while loop doesn't get executed. How can you possibly get stuck? Neither Serial.available() or Serial.read() are blocking functions.
But that bit of code is still a crummy solution.
First, the buffer size if only 128 bytes. It wouldn't take that long to read and discard the entire buffer.
Second, there are very few legitimate uses of the flush function.