/* * Copyright (c) 2022, MacDue * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace Core { template auto debounce(TFunction function, int timeout) { RefPtr timer; return [=](T... args) mutable { auto apply_function = [=] { function(args...); }; if (timer) { timer->stop(); timer->on_timeout = move(apply_function); } else { timer = Core::Timer::create_single_shot(timeout, move(apply_function)).release_value_but_fixme_should_propagate_errors(); } timer->start(); }; }; }