Nui
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
throttle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4
6
7namespace Nui
8{
10 {
11 public:
13 ThrottledFunction(int32_t id, bool calledWhenReady, std::function<void()> func);
16 ThrottledFunction(ThrottledFunction&& other) noexcept;
19
21 void operator()();
22
24 bool valid() const;
25
26 private:
27 int32_t id_;
28 bool calledWhenReady_;
29 std::function<void()> func_{};
30 };
31
42 void throttle(
43 int milliseconds,
44 std::function<void()> toWrap,
45 std::function<void(ThrottledFunction&&)> callback,
46 bool callWhenReady = false);
47}
Definition throttle.hpp:10
~ThrottledFunction()
Definition throttle.cpp:20
ThrottledFunction(ThrottledFunction const &)=delete
void operator()()
Calls the function if it is valid.
Definition throttle.cpp:46
ThrottledFunction()
Definition throttle.cpp:8
ThrottledFunction & operator=(ThrottledFunction const &)=delete
bool valid() const
Returns true if this object contains a valid function.
Definition throttle.cpp:52
Definition file_dialog.hpp:6
void throttle(int milliseconds, std::function< void()> toWrap, std::function< void(ThrottledFunction &&)> callback, bool callWhenReady=false)
Creates a function that can be used to call a function at most once during the specified interval.
Definition throttle.cpp:57