When investing into any kind of technology, that's a risk you have to take.
If you purchase a gasoline car, is gasoline available in 10 years' time or has electricity killed it?
Similarly, if you purchase an EF lens, is mirrorless the thing in 10 years' time?
Fortunately, in the case of EF lenses, the adapter to fit it to a mirrorless RF camera is available and very convenient. The adapter to make electricity into gasoline is a very heavy and inconvenient factory which is expensive to run.
At least when purchasing an EF lens, you aren't restricting yourself to APS-C sized sensors. I'd say APS-C lenses are perhaps the lenses that are more at danger due to full frame becoming less expensive over time, with the greatest danger being obviously EF-M.
Also, Canon has a higher market share than Nikon, so the chances of EF becoming obsolete are less than they are with Nikon stuff becoming obsolete. (Edit: of course I don't mean that Nikon will become obsolete, as any market really requires at least two competitors, or else the only player in the market would select so expensive prices that the prices would attract competitors)
I wouldn't wait for new RF lenses to become available. If I purchased an RF camera, I would use whatever lenses are available for the EF mount and use them with an adapter.
An EF lens is a purchase that will stay useful for 10 years.