add wait method that blocks until all tasks are processed