How to wait for all processes to exit

I created many processes, and how to quit after the main process waits for all processes to be executed.

Now I use Process.sleep(60000)

1 Like

It seems Tasks can help You. You can start many tasks and await for them to finish their work.

2 Likes

Put your processes under a supervisor in your app’s supervision tree, it will wait for them to finish (up to a configurable limit) before shutting down.

https://hexdocs.pm/elixir/Supervisor.html#module-start-and-shutdown

If you use tasks this is easy to do with Task.Supervisor.

2 Likes

thanks