1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +00:00

LibCore+Userland: Don't auto-start new Core::Timers

This was unintuitive, and only useful in a few cases. In the majority,
users had to immediately call `stop()`, and several who did want the
timer started would call `start()` on it immediately anyway. Case in
point: There are only two places I had to add a manual `start()`.
This commit is contained in:
Sam Atkins 2023-01-11 19:36:46 +00:00 committed by Andreas Kling
parent a8cf0c9371
commit 6edc0cf5ab
10 changed files with 12 additions and 8 deletions

View file

@ -17,8 +17,8 @@ Timer::Timer(Object* parent)
Timer::Timer(int interval_ms, Function<void()>&& timeout_handler, Object* parent)
: Object(parent)
, on_timeout(move(timeout_handler))
, m_interval_ms(interval_ms)
{
start(interval_ms);
}
void Timer::start()

View file

@ -18,15 +18,12 @@ class Timer final : public Object {
public:
static ErrorOr<NonnullRefPtr<Timer>> create_repeating(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
{
auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
timer->stop();
return timer;
return adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent));
}
static ErrorOr<NonnullRefPtr<Timer>> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
{
auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
timer->set_single_shot(true);
timer->stop();
return timer;
}