Sebastian Jansson | 6ce033a | 2020-01-22 10:12:56 +0100 | [diff] [blame^] | 1 | /* |
| 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 | |
| 12 | namespace webrtc { |
| 13 | bool 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 |