Async flushing and safe shutdown.