LeechCraft
0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
future.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 <coroutine>
12
#include <QFuture>
13
#include <QFutureWatcher>
14
#include "
taskfwd.h
"
15
16
namespace
LC::Util::detail
17
{
18
template
<
typename
R>
19
struct
FutureAwaiter
20
{
21
QFutureWatcher<R>
Watcher_
;
22
23
FutureAwaiter
(
const
QFuture<R>
& future)
24
{
25
Watcher_
.setFuture (future);
26
}
27
28
bool
await_ready
() const noexcept
29
{
30
return
Watcher_
.future ().isFinished ();
31
}
32
33
void
await_suspend
(std::coroutine_handle<> handle)
noexcept
34
{
35
QObject::connect (&
Watcher_
,
36
&QFutureWatcher<R>::finished,
37
handle);
38
}
39
40
R
await_resume
() const noexcept
41
{
42
if
constexpr
(!std::is_same_v<R, void>)
43
return
Watcher_
.future ().result ();
44
}
45
};
46
}
47
48
namespace
LC::Util
49
{
50
template
<
typename
R>
51
detail::FutureAwaiter<R>
GetAwaiter
(
QFuture<R>
future,
AwaiterCPO
)
52
{
53
return
{ future };
54
}
55
}
56
57
namespace
LC
58
{
59
template
<
typename
R>
60
auto
operator
co_await
(
QFuture<R>
future)
61
{
62
return
Util::GetAwaiter
(std::move (future), {});
63
}
64
}
QFuture
Definition
idownload.h:17
LC::Util::detail
Definition
fancytrayiconfreedesktop.cpp:24
LC::Util
Definition
icoreproxy.h:34
LC::Util::GetAwaiter
detail::EitherAwaiter< L, R, std::identity > GetAwaiter(const Either< L, R > &either, AwaiterCPO)
Definition
either.h:119
LC
Definition
constants.h:15
LC::Util::AwaiterCPO
Definition
taskfwd.h:22
LC::Util::detail::FutureAwaiter
Definition
future.h:20
LC::Util::detail::FutureAwaiter::await_ready
bool await_ready() const noexcept
Definition
future.h:28
LC::Util::detail::FutureAwaiter::FutureAwaiter
FutureAwaiter(const QFuture< R > &future)
Definition
future.h:23
LC::Util::detail::FutureAwaiter::await_suspend
void await_suspend(std::coroutine_handle<> handle) noexcept
Definition
future.h:33
LC::Util::detail::FutureAwaiter::Watcher_
QFutureWatcher< R > Watcher_
Definition
future.h:21
LC::Util::detail::FutureAwaiter::await_resume
R await_resume() const noexcept
Definition
future.h:40
taskfwd.h
src
util
threads
coro
future.h
Generated by
1.18.0