LeechCraft 0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
timer.h
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#pragma once
10
11#include <chrono>
12#include <coroutine>
13#include <QTimer>
14#include "taskfwd.h"
15#include "../threadsconfig.h"
16
17namespace LC::Util
18{
19 namespace detail
20 {
22 {
23 QTimer Timer_;
24
25 explicit TimerAwaiter (std::chrono::milliseconds duration, Qt::TimerType precision);
26
27 bool await_ready () const noexcept;
28 void await_suspend (std::coroutine_handle<> handle) noexcept;
29 void await_resume () const noexcept;
30 };
31 }
32
33 template<Qt::TimerType Precision>
35 {
36 std::chrono::milliseconds Duration_;
37
38 auto operator co_await () const
39 {
40 return detail::TimerAwaiter { Duration_, Precision };
41 }
42 };
43
47
48 inline detail::TimerAwaiter GetAwaiter (std::chrono::milliseconds duration, AwaiterCPO)
49 {
50 return detail::TimerAwaiter { duration, Qt::CoarseTimer };
51 }
52}
53
54namespace LC
55{
56 inline auto operator co_await (std::chrono::milliseconds duration)
57 {
58 return Util::GetAwaiter (duration, {});
59 }
60}
detail::EitherAwaiter< L, R, std::identity > GetAwaiter(const Either< L, R > &either, AwaiterCPO)
Definition either.h:119
WithPrecision< Qt::PreciseTimer > Precisely
Definition timer.h:44
WithPrecision< Qt::VeryCoarseTimer > VeryCoarsely
Definition timer.h:46
WithPrecision< Qt::CoarseTimer > Coarsely
Definition timer.h:45
Definition constants.h:15
std::chrono::milliseconds Duration_
Definition timer.h:36
bool await_ready() const noexcept
Definition timer.cpp:20
TimerAwaiter(std::chrono::milliseconds duration, Qt::TimerType precision)
Definition timer.cpp:13
void await_resume() const noexcept
Definition timer.cpp:31
void await_suspend(std::coroutine_handle<> handle) noexcept
Definition timer.cpp:25
#define UTIL_THREADS_API