https://github.com/versusvoid/qcosignal
Qt bound coroutines
https://github.com/versusvoid/qcosignal
async-await coroutines cpp cpp20 qt
Last synced: 2 months ago
JSON representation
Qt bound coroutines
- Host: GitHub
- URL: https://github.com/versusvoid/qcosignal
- Owner: versusvoid
- License: mit
- Created: 2025-06-03T12:42:06.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-03T13:12:28.000Z (about 1 year ago)
- Last Synced: 2025-06-03T23:24:17.523Z (about 1 year ago)
- Topics: async-await, coroutines, cpp, cpp20, qt
- Language: C++
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Qt bound coroutines
Basic coroutines implementation in [single header](qcosignal.hpp) for exactly two use-cases:
1. awaiting for some signal:
```cpp
...
co_await CoSignal(sender, &Sender::signal);
...
```
2. awaiting for concurrent result:
```cpp
...
QString result = co_await QtConcurrent::run(&concurrent_function_with_result, arg);
...
```
Coroutines are defined as methods of `QObject`-derived class:
```cpp
Async<> MyObject::testAwaitFutureWithResult()
{
qDebug() << "awaiting concurrent future";
QString result = co_await QtConcurrent::run(&concurrent_with_result, 1);
qDebug() << "concurrent future result:" << result;
}
```
and are bound to `QObject* this` (i.e. destroyed when `this` is destroyed).
Coroutine awaiting on signal will also be destroyed if expected sender is destroyed,
so there won't be indefinite hangs.
Implementation is missing some opportunities for move-semantics optimization, but I'm lacking
enough instinctive understanding of it in C++.
Probably not "serious production"-ready, but fully intended to be used in my pet project and
extended as necessary.