1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:07:36 +00:00

LibCore: Add Core::Timer::create_single_shot()

This is just a convenience function for creating single-shot timers.
This commit is contained in:
Andreas Kling 2020-04-07 22:15:22 +02:00
parent f813041f67
commit a53cf81374
4 changed files with 33 additions and 35 deletions

View file

@ -32,8 +32,16 @@
namespace Core {
class Timer final : public Object {
C_OBJECT(Timer)
C_OBJECT(Timer);
public:
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));
timer->set_single_shot(true);
return timer;
}
virtual ~Timer() override;
void start();

View file

@ -62,12 +62,9 @@ Document::Document()
, m_style_resolver(make<StyleResolver>(*this))
, m_window(Window::create_with_document(*this))
{
m_style_update_timer = Core::Timer::construct();
m_style_update_timer->set_single_shot(true);
m_style_update_timer->set_interval(0);
m_style_update_timer->on_timeout = [this] {
m_style_update_timer = Core::Timer::create_single_shot(0, [this] {
update_style();
};
});
}
Document::~Document()