mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
C++: add blocking_invoke_from_event_loop
A blocking version of invoke_from_event_loop
This commit is contained in:
parent
ce62cce266
commit
092d5d551f
3 changed files with 76 additions and 0 deletions
|
@ -56,3 +56,23 @@ TEST_CASE("Event from thread")
|
|||
REQUIRE(called == 110);
|
||||
t.join();
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Blocking Event from thread")
|
||||
{
|
||||
std::atomic<int> called = 0;
|
||||
auto t = std::thread([&] {
|
||||
// test returning a, unique_ptr because it is movable-only
|
||||
std::unique_ptr foo = sixtyfps::blocking_invoke_from_event_loop([&] {
|
||||
return std::make_unique<int>(42);
|
||||
});
|
||||
called = *foo;
|
||||
sixtyfps::invoke_from_event_loop([&] {
|
||||
sixtyfps::quit_event_loop();
|
||||
});
|
||||
});
|
||||
|
||||
sixtyfps::run_event_loop();
|
||||
REQUIRE(called == 42);
|
||||
t.join();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue