blob: e27ceb3eb3ceff32fc3bd4a921ae9ddef322b80f [file] [log] [blame]
Marc Olberding1e17db52025-08-27 12:25:28 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2025 NVIDIA
3
4#include "utilities.hpp"
5
6#include <chrono>
7#include <filesystem>
8#include <format>
9#include <iostream>
10#include <thread>
11
12using namespace std::chrono_literals;
13
14void sleep_milliseconds(std::chrono::milliseconds milliseconds)
15{
16 std::cerr << std::format("Sleeping for {} milliseconds\n",
17 milliseconds.count());
18 std::this_thread::sleep_for(milliseconds);
19}
20
21void wait_for_path_to_exist(std::string_view path,
22 std::chrono::milliseconds timeout)
23{
24 while (true)
25 {
26 std::error_code ec;
27 bool exists = std::filesystem::exists(path, ec);
28 if (exists)
29 {
30 return;
31 }
32 sleep_milliseconds(1ms);
33 timeout -= 1ms;
34 }
35 std::cerr << std::format("Failed to wait for {} to exist", path);
36}