Repeat calling a function with variable repeat time and the ability to be stopped.

I’m writing some code to spawn enemies at a rate that changes during play.
I started by using InvokeRepeat but soon realised that I needed another solution because InvokeRepeat won’t let me alter the repeat time once it’s been called.

I found a solution where someone suggests just using the standard Invoke with my spawnRate variable at the end of my spawnEnemy function. This works but it seems a bit uncontrolled. How would I ever stop is calling once it’s been called once?

Does anyone have a better solution?

    private void SpawnEnemy()
    {
        GameObject enemyInstance = Instantiate(enemyPB, nextSpawnPos, Quaternion.identity, transform);
        Invoke("SpawnEnemy", spawnRate);

    }

Ignore me.

CancelInvoke is the answer.