ladybird/Libraries/LibWeb/Platform/Timer.cpp
Shannon Booth f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00

44 lines
1.1 KiB
C++

/*
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGC/Function.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/Platform/Timer.h>
namespace Web::Platform {
Timer::~Timer() = default;
void Timer::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(on_timeout);
}
GC::Ref<Timer> Timer::create(GC::Heap& heap)
{
return EventLoopPlugin::the().create_timer(heap);
}
GC::Ref<Timer> Timer::create_repeating(GC::Heap& heap, int interval_ms, GC::Ptr<GC::Function<void()>> timeout_handler)
{
auto timer = EventLoopPlugin::the().create_timer(heap);
timer->set_single_shot(false);
timer->set_interval(interval_ms);
timer->on_timeout = move(timeout_handler);
return timer;
}
GC::Ref<Timer> Timer::create_single_shot(GC::Heap& heap, int interval_ms, GC::Ptr<GC::Function<void()>> timeout_handler)
{
auto timer = EventLoopPlugin::the().create_timer(heap);
timer->set_single_shot(true);
timer->set_interval(interval_ms);
timer->on_timeout = move(timeout_handler);
return timer;
}
}