Anywhere, it is enough to have filed an application. A patent is not granted if the known technology at the filing date makes the invention obvious or not novel.
What happens afterwards doesn't matter for that specific patents. It does matter for following patents of improvements for example because bringing a product to market counts as publishing it.
There is a grace period in the US and some more places (not EU or other big countries though!) Which gives you some time to file after your own publication. Don't use that if you want your patent anywhere outside the US because it even impedes a PCT application originating from the US one.