KiCad PCB EDA Suite
Loading...
Searching...
No Matches
throttle.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <chrono>
23
31{
32public:
33 explicit THROTTLE( std::chrono::milliseconds aInterval ) :
34 m_interval( aInterval ),
35 m_last( std::chrono::steady_clock::now() - aInterval )
36 {
37 }
38
44 bool Ready()
45 {
46 auto now = std::chrono::steady_clock::now();
47
48 if( now - m_last >= m_interval )
49 {
50 m_last = now;
51 return true;
52 }
53
54 return false;
55 }
56
57private:
58 std::chrono::milliseconds m_interval;
59 std::chrono::steady_clock::time_point m_last;
60};
std::chrono::milliseconds m_interval
Definition throttle.h:58
bool Ready()
Definition throttle.h:44
THROTTLE(std::chrono::milliseconds aInterval)
Definition throttle.h:33
std::chrono::steady_clock::time_point m_last
Definition throttle.h:59
STL namespace.