Serenity Operating System
1/*
2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/NonnullRefPtr.h>
8#include <LibWeb/Platform/EventLoopPlugin.h>
9#include <LibWeb/Platform/Timer.h>
10
11namespace Web::Platform {
12
13Timer::~Timer() = default;
14
15NonnullRefPtr<Timer> Timer::create()
16{
17 return EventLoopPlugin::the().create_timer();
18}
19
20NonnullRefPtr<Timer> Timer::create_repeating(int interval_ms, JS::SafeFunction<void()>&& timeout_handler)
21{
22 auto timer = EventLoopPlugin::the().create_timer();
23 timer->set_single_shot(false);
24 timer->set_interval(interval_ms);
25 timer->on_timeout = move(timeout_handler);
26 return timer;
27}
28
29NonnullRefPtr<Timer> Timer::create_single_shot(int interval_ms, JS::SafeFunction<void()>&& timeout_handler)
30{
31 auto timer = EventLoopPlugin::the().create_timer();
32 timer->set_single_shot(true);
33 timer->set_interval(interval_ms);
34 timer->on_timeout = move(timeout_handler);
35 return timer;
36}
37
38}