2022-09-07 20:30:31 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-09-07 20:30:31 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Function.h>
|
2022-09-07 20:30:31 +02:00
|
|
|
#include <LibWeb/Platform/EventLoopPlugin.h>
|
|
|
|
#include <LibWeb/Platform/Timer.h>
|
|
|
|
|
|
|
|
namespace Web::Platform {
|
|
|
|
|
|
|
|
Timer::~Timer() = default;
|
|
|
|
|
2024-10-30 21:42:05 +13:00
|
|
|
void Timer::visit_edges(JS::Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
visitor.visit(on_timeout);
|
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Timer> Timer::create(GC::Heap& heap)
|
2022-09-07 20:30:31 +02:00
|
|
|
{
|
2024-10-30 21:37:08 +13:00
|
|
|
return EventLoopPlugin::the().create_timer(heap);
|
2022-09-07 20:30:31 +02:00
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Timer> Timer::create_repeating(GC::Heap& heap, int interval_ms, GC::Ptr<GC::Function<void()>> timeout_handler)
|
2022-09-07 20:30:31 +02:00
|
|
|
{
|
2024-10-30 21:37:08 +13:00
|
|
|
auto timer = EventLoopPlugin::the().create_timer(heap);
|
2022-09-07 20:30:31 +02:00
|
|
|
timer->set_single_shot(false);
|
|
|
|
timer->set_interval(interval_ms);
|
|
|
|
timer->on_timeout = move(timeout_handler);
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Timer> Timer::create_single_shot(GC::Heap& heap, int interval_ms, GC::Ptr<GC::Function<void()>> timeout_handler)
|
2022-09-07 20:30:31 +02:00
|
|
|
{
|
2024-10-30 21:37:08 +13:00
|
|
|
auto timer = EventLoopPlugin::the().create_timer(heap);
|
2022-09-07 20:30:31 +02:00
|
|
|
timer->set_single_shot(true);
|
|
|
|
timer->set_interval(interval_ms);
|
|
|
|
timer->on_timeout = move(timeout_handler);
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|