Wait for task completion before returning