mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
C++: Fixed sixtyfps::blocking_invoke_from_main_loop
when the callable returns void
Fixes #623
This commit is contained in:
parent
a102e9ed8d
commit
d26e95fb95
3 changed files with 21 additions and 2 deletions
|
@ -855,7 +855,7 @@ void invoke_from_event_loop(Functor f)
|
|||
/// ...
|
||||
/// }
|
||||
/// ```
|
||||
template<typename Functor>
|
||||
template<typename Functor, typename = std::enable_if_t<!std::is_void_v<std::invoke_result_t<Functor>>>>
|
||||
auto blocking_invoke_from_event_loop(Functor f) -> std::invoke_result_t<Functor> {
|
||||
std::optional<std::invoke_result_t<Functor>> result;
|
||||
std::mutex mtx;
|
||||
|
@ -871,6 +871,21 @@ auto blocking_invoke_from_event_loop(Functor f) -> std::invoke_result_t<Functor>
|
|||
return std::move(*result);
|
||||
}
|
||||
|
||||
template<typename Functor, typename = std::enable_if_t<std::is_void_v<std::invoke_result_t<Functor>>>>
|
||||
auto blocking_invoke_from_event_loop(Functor f) -> void {
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
bool ok = false;
|
||||
invoke_from_event_loop([&] {
|
||||
f();
|
||||
std::unique_lock lock(mtx);
|
||||
ok = true;
|
||||
cv.notify_one();
|
||||
});
|
||||
std::unique_lock lock(mtx);
|
||||
cv.wait(lock, [&] { return ok; });
|
||||
}
|
||||
|
||||
namespace private_api {
|
||||
|
||||
/// Registers a font by the specified path. The path must refer to an existing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue