how can i create a terrain with a procedural function without freeze.

  1. optimize your generation processes
  2. generate small chuncks/pieces by timer/tick

For example, see how the map is generated in Factorio when creating the world