LeechCraft
0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
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
15
namespace
LC::Util::detail
16
{
17
template
<
typename
R>
18
struct
FutureAwaiter
19
{
20
QFutureWatcher<R>
Watcher_
;
21
22
FutureAwaiter
(
const
QFuture<R>
& future)
23
{
24
Watcher_
.setFuture (future);
25
}
26
27
bool
await_ready
() const noexcept
28
{
29
return
Watcher_
.future ().isFinished ();
30
}
31
32
void
await_suspend
(std::coroutine_handle<> handle)
noexcept
33
{
34
QObject::connect (&
Watcher_
,
35
&QFutureWatcher<R>::finished,
36
handle);
37
}
38
39
R
await_resume
() const noexcept
40
{
41
if
constexpr
(!std::is_same_v<R, void>)
42
return
Watcher_
.future ().result ();
43
}
44
};
45
}
46
47
namespace
LC
48
{
49
template
<
typename
R>
50
Util::detail::FutureAwaiter<R>
operator
co_await
(
QFuture<R>
future)
51
{
52
return
{ future };
53
}
54
}
QFuture
Definition
idownload.h:17
LC::Util::detail
Definition
fancytrayiconfreedesktop.cpp:24
LC
Definition
constants.h:15
LC::Util::detail::FutureAwaiter
Definition
future.h:19
LC::Util::detail::FutureAwaiter::await_ready
bool await_ready() const noexcept
Definition
future.h:27
LC::Util::detail::FutureAwaiter::FutureAwaiter
FutureAwaiter(const QFuture< R > &future)
Definition
future.h:22
LC::Util::detail::FutureAwaiter::await_suspend
void await_suspend(std::coroutine_handle<> handle) noexcept
Definition
future.h:32
LC::Util::detail::FutureAwaiter::Watcher_
QFutureWatcher< R > Watcher_
Definition
future.h:20
LC::Util::detail::FutureAwaiter::await_resume
R await_resume() const noexcept
Definition
future.h:39
src
util
threads
coro
future.h
Generated by
1.13.2