-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
qt_standard_project_setup() | ||
|
||
qt_add_executable(testqt testqt.cpp) | ||
|
||
set_property(TARGET testqt PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
set_target_properties(testqt PROPERTIES FOLDER "ucoro_tests") | ||
target_link_libraries(testqt PRIVATE ucoro Qt6::Core) | ||
|
||
add_test(NAME testqt COMMAND testqt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
|
||
#include <iostream> | ||
#include "ucoro/awaitable.hpp" | ||
#include <QtCore> | ||
#include <QTimer> | ||
#include <QCoreApplication> | ||
|
||
ucoro::awaitable<int> coro_compute_int(int value) | ||
{ | ||
auto ret = co_await executor_awaitable<int>([value](auto handle) { | ||
QTimer::singleShot(0, [value, handle = std::move(handle)]() mutable { | ||
std::this_thread::sleep_for(std::chrono::seconds(0)); | ||
std::cout << value << " value\n"; | ||
handle(value * 100); | ||
}); | ||
}); | ||
|
||
co_return (value + ret); | ||
} | ||
|
||
ucoro::awaitable<void> coro_compute_exec(int value) | ||
{ | ||
auto ret = co_await coro_compute_int(value); | ||
std::cout << "return: " << ret << std::endl; | ||
co_return; | ||
} | ||
|
||
ucoro::awaitable<void> coro_compute() | ||
{ | ||
auto x = co_await ucoro::local_storage; | ||
std::cout << "local storage: " << std::any_cast<std::string>(x) << std::endl; | ||
|
||
for (auto i = 0; i < 100; i++) | ||
{ | ||
co_await coro_compute_exec(i); | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
std::string str = "hello"; | ||
|
||
QCoreApplication app(argc, argv); | ||
|
||
coro_start(coro_compute(), str); | ||
|
||
app.exec(); | ||
return 0; | ||
} |