Gazebo Transport

API Reference

15.0.2
WaitHelpers.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17
18#ifndef GZ_TRANSPORT_WAITHELPERS_HH_
19#define GZ_TRANSPORT_WAITHELPERS_HH_
20
21#include <chrono>
22#include <string>
23#include <thread>
24
25#include "gz/transport/config.hh"
26#include "gz/transport/Export.hh"
27
28namespace gz::transport
29{
30 // Inline bracket to help doxygen filtering.
31 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
32 //
33 // Forward declaration.
34 class Node;
35
39 void GZ_TRANSPORT_VISIBLE waitForShutdown();
40
50 template <typename Pred>
51 bool waitUntil(Pred _pred,
56 {
57 auto deadline = std::chrono::steady_clock::now() + _timeout;
58 while (std::chrono::steady_clock::now() < deadline)
59 {
60 if (_pred())
61 return true;
63 }
64 return _pred();
65 }
66
72 bool GZ_TRANSPORT_VISIBLE waitForService(
73 const Node &_node,
74 const std::string &_service,
77
83 bool GZ_TRANSPORT_VISIBLE waitForTopic(
84 const Node &_node,
85 const std::string &_topic,
88 }
89}
90
91// GZ_TRANSPORT_WAITHELPERS_HH_
92#endif