Await completion of pending tasks before shutdown