1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 10:18:15 +09:00
ladybird/LibCore/CTimer.cpp
Andreas Kling a3e8fc3d9c LibCore: Add a convenience constructor for CTimer.
new CTimer(250, [] { thing_to_do_every_250_msec(); });
2019-04-14 05:44:15 +02:00

47 lines
701 B
C++

#include <LibCore/CTimer.h>
CTimer::CTimer(CObject* parent)
: CObject(parent)
{
}
CTimer::CTimer(int interval, Function<void()>&& timeout_handler, CObject* parent)
: CObject(parent)
, on_timeout(move(timeout_handler))
{
start(interval);
}
CTimer::~CTimer()
{
}
void CTimer::start()
{
start(m_interval);
}
void CTimer::start(int interval)
{
if (m_active)
return;
m_interval = interval;
start_timer(interval);
m_active = true;
}
void CTimer::stop()
{
if (!m_active)
return;
stop_timer();
m_active = false;
}
void CTimer::timer_event(CTimerEvent&)
{
if (m_single_shot)
stop();
if (on_timeout)
on_timeout();
}