Skip to content

Commit 28f6d05

Browse files
committed
Allow void return value in runOnThreadPool
1 parent fc3ca8b commit 28f6d05

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/coroutines/threadpool.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ namespace tremotesf {
4747
if (mSharedData->unhandledException) {
4848
std::rethrow_exception(mSharedData->unhandledException);
4949
}
50-
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
51-
return std::move(mSharedData->result).value();
50+
if constexpr (!std::is_void_v<T>) {
51+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
52+
return std::move(mSharedData->result).value();
53+
}
5254
}
5355

5456
private:
57+
struct Empty {};
58+
using ResultValue = std::conditional_t<std::is_void_v<T>, Empty, T>;
5559
struct SharedData {
5660
QObject receiver{};
5761
std::atomic_bool cancelled{};
58-
std::optional<T> result{};
62+
std::optional<ResultValue> result{};
5963
std::exception_ptr unhandledException{};
6064
std::coroutine_handle<> coroutineHandle{};
6165
};
@@ -75,7 +79,11 @@ namespace tremotesf {
7579
windowsSetUpFatalErrorHandlersInThread();
7680
#endif
7781
try {
78-
mSharedData->result = mFunction();
82+
if constexpr (std::is_void_v<T>) {
83+
mFunction();
84+
} else {
85+
mSharedData->result = mFunction();
86+
}
7987
} catch (...) {
8088
mSharedData->unhandledException = std::current_exception();
8189
}

0 commit comments

Comments
 (0)