/* * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::Platform { class Timer : public JS::Cell { GC_CELL(Timer, JS::Cell); GC_DECLARE_ALLOCATOR(Timer); public: static GC::Ref create(GC::Heap&); static GC::Ref create_repeating(GC::Heap&, int interval_ms, GC::Ptr> timeout_handler); static GC::Ref create_single_shot(GC::Heap&, int interval_ms, GC::Ptr> timeout_handler); virtual ~Timer(); void start(); void start(int interval_ms); void restart(); void restart(int interval_ms); void stop(); void set_active(bool); bool is_active() const; int interval() const; void set_interval(int interval_ms); bool is_single_shot() const; void set_single_shot(bool); GC::Ptr> on_timeout; private: Timer(); virtual void visit_edges(JS::Cell::Visitor&) override; NonnullRefPtr m_timer; }; }