Wait for the tasks to finish with a mainloop