LibCore: Add Timer::create_repeating convenience method

This commit is contained in:
Tom 2021-03-27 14:33:31 -06:00 committed by Andreas Kling
commit 7269e0f751
Notes: sideshowbarker 2024-07-18 20:59:40 +09:00

View file

@ -35,6 +35,12 @@ class Timer final : public Object {
C_OBJECT(Timer); C_OBJECT(Timer);
public: public:
static NonnullRefPtr<Timer> create_repeating(int interval, Function<void()>&& timeout_handler, Object* parent = nullptr)
{
auto timer = adopt(*new Timer(interval, move(timeout_handler), parent));
timer->stop();
return timer;
}
static NonnullRefPtr<Timer> create_single_shot(int interval, Function<void()>&& timeout_handler, Object* parent = nullptr) static NonnullRefPtr<Timer> create_single_shot(int interval, Function<void()>&& timeout_handler, Object* parent = nullptr)
{ {
auto timer = adopt(*new Timer(interval, move(timeout_handler), parent)); auto timer = adopt(*new Timer(interval, move(timeout_handler), parent));