timer_rpl.h 884 B

12345678910111213141516171819202122232425262728293031323334
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "base/timer.h"
  9. namespace base {
  10. [[nodiscard]] inline auto timer_once(crl::time delay) {
  11. return rpl::make_producer<>([=](const auto &consumer) {
  12. auto result = rpl::lifetime();
  13. result.make_state<base::Timer>([=] {
  14. consumer.put_next_copy(rpl::empty);
  15. consumer.put_done();
  16. })->callOnce(delay);
  17. return result;
  18. });
  19. }
  20. [[nodiscard]] inline auto timer_each(crl::time delay) {
  21. return rpl::make_producer<>([=](const auto &consumer) {
  22. auto result = rpl::lifetime();
  23. result.make_state<base::Timer>([=] {
  24. consumer.put_next_copy(rpl::empty);
  25. })->callEach(delay);
  26. return result;
  27. });
  28. }
  29. } // namespace base