blob: 26fe69cce193842571771af58fb71ce5c1269376 [file] [log] [blame]
Sebastian Jansson6ce033a2020-01-22 10:12:56 +01001/*
2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#include "api/test/time_controller.h"
11
12namespace webrtc {
13bool TimeController::Wait(const std::function<bool()>& done,
14 TimeDelta max_duration) {
15 // Step size is chosen to be short enough to not significantly affect latency
16 // in real time tests while being long enough to avoid adding too much load to
17 // the system.
18 const auto kStep = TimeDelta::ms(5);
19 for (auto elapsed = TimeDelta::Zero(); elapsed < max_duration;
20 elapsed += kStep) {
21 if (done())
22 return true;
23 AdvanceTime(kStep);
24 }
25 return done();
26}
27} // namespace webrtc