LeechCraft
0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
getresult.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 <type_traits>
12
#include <QEventLoop>
13
#include "
task.h
"
14
15
namespace
LC::Util
16
{
17
template
<
typename
T,
template
<
typename
>
typename
... Extensions>
18
T
GetTaskResult
(
Task<T, Extensions...>
task
)
19
{
20
constexpr
bool
isVoid
= std::is_same_v<T, void>;
21
std::conditional_t<isVoid, void*, std::unique_ptr<T>>
result
;
22
23
std::exception_ptr exception;
24
25
QEventLoop
loop
;
26
bool
done =
false
;
27
[] (
auto
task
,
auto
&
result
,
auto
& exception,
auto
& done,
auto
&
loop
) ->
Task<void>
28
{
29
try
30
{
31
if
constexpr
(
isVoid
)
32
co_await
task
;
33
else
34
result
= std::make_unique<T> (
co_await
task
);
35
}
36
catch
(...)
37
{
38
exception = std::current_exception ();
39
}
40
done =
true
;
41
loop
.quit ();
42
} (
task
,
result
, exception, done,
loop
);
43
if
(!done)
44
loop
.exec ();
45
46
if
(exception)
47
std::rethrow_exception (exception);
48
49
if
constexpr
(!
isVoid
)
50
return
*
result
;
51
}
52
}
LC::Util::Task
Definition
task.h:94
LC::Util
Definition
icoreproxy.h:34
LC::Util::Filter
Container< T > Filter(const Container< T > &c, F f)
Definition
prelude.h:118
LC::Util::GetTaskResult
T GetTaskResult(Task< T, Extensions... > task)
Definition
getresult.h:18
task.h
src
util
threads
coro
getresult.h
Generated by
1.10.0