That reminds me of a blog article I wrote some time ago, where “timeout” gets mentioned:
https://gaultier.github.io/blog/way_too_many_ways_to_wait_fo...
It’s more useful if you are implementing this in a general programming language, not in the shell, or if you want to know how it works under the hood.