/src/serenity/Userland/Libraries/LibWeb/Platform/Timer.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
11 | | namespace Web::Platform { |
12 | | |
13 | 0 | Timer::~Timer() = default; |
14 | | |
15 | | NonnullRefPtr<Timer> Timer::create() |
16 | 0 | { |
17 | 0 | return EventLoopPlugin::the().create_timer(); |
18 | 0 | } |
19 | | |
20 | | NonnullRefPtr<Timer> Timer::create_repeating(int interval_ms, JS::SafeFunction<void()>&& timeout_handler) |
21 | 0 | { |
22 | 0 | auto timer = EventLoopPlugin::the().create_timer(); |
23 | 0 | timer->set_single_shot(false); |
24 | 0 | timer->set_interval(interval_ms); |
25 | 0 | timer->on_timeout = move(timeout_handler); |
26 | 0 | return timer; |
27 | 0 | } |
28 | | |
29 | | NonnullRefPtr<Timer> Timer::create_single_shot(int interval_ms, JS::SafeFunction<void()>&& timeout_handler) |
30 | 0 | { |
31 | 0 | auto timer = EventLoopPlugin::the().create_timer(); |
32 | 0 | timer->set_single_shot(true); |
33 | 0 | timer->set_interval(interval_ms); |
34 | 0 | timer->on_timeout = move(timeout_handler); |
35 | 0 | return timer; |
36 | 0 | } |
37 | | |
38 | | } |