LeechCraft 0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
timer.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "timer.h"
10#include <QTimer>
11
12namespace LC::Util::detail
13{
14 TimerAwaiter::TimerAwaiter (std::chrono::milliseconds duration, Qt::TimerType precision)
15 {
16 Timer_.setSingleShot (true);
17 Timer_.setInterval (duration);
18 Timer_.setTimerType (precision);
19 }
20
21 bool TimerAwaiter::await_ready () const noexcept
22 {
23 return false;
24 }
25
26 void TimerAwaiter::await_suspend (std::coroutine_handle<> handle) noexcept
27 {
28 QObject::connect (&Timer_,
29 &QTimer::timeout,
30 [handle]
31 {
32 if (!handle.done ())
33 handle ();
34 });
35 Timer_.start ();
36 }
37
38 void TimerAwaiter::await_resume () const noexcept
39 {
40 }
41}
42
43namespace LC
44{
45 Util::detail::TimerAwaiter operator co_await (std::chrono::milliseconds duration)
46 {
47 return Util::detail::TimerAwaiter { duration, Qt::CoarseTimer };
48 }
49}
Definition constants.h:15
bool await_ready() const noexcept
Definition timer.cpp:21
TimerAwaiter(std::chrono::milliseconds duration, Qt::TimerType precision)
Definition timer.cpp:14
void await_resume() const noexcept
Definition timer.cpp:38
void await_suspend(std::coroutine_handle<> handle) noexcept
Definition timer.cpp:26