Serenity Operating System
1/*
2 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <LibWeb/HTML/Timer.h>
8#include <LibWeb/HTML/Window.h>
9#include <LibWeb/Platform/Timer.h>
10
11namespace Web::HTML {
12
13JS::NonnullGCPtr<Timer> Timer::create(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
14{
15 return window.heap().allocate_without_realm<Timer>(window, milliseconds, move(callback), id);
16}
17
18Timer::Timer(Window& window, i32 milliseconds, Function<void()> callback, i32 id)
19 : m_window(window)
20 , m_callback(move(callback))
21 , m_id(id)
22{
23 m_timer = Platform::Timer::create_single_shot(milliseconds, [this] {
24 m_callback();
25 });
26}
27
28void Timer::visit_edges(Cell::Visitor& visitor)
29{
30 Base::visit_edges(visitor);
31 visitor.visit(m_window.ptr());
32}
33
34Timer::~Timer()
35{
36}
37
38void Timer::start()
39{
40 m_timer->start();
41}
42
43}