libQuotient
libQuotient copied to clipboard
Jobs as promises
To start using libqmatrixclient, one has to connect
to quite a bit jobs, which means a lot of boilerplate code binding to the same success
signal of another job. Meanwhile everybody around uses promises/futures; so why don't we. A shortcut like callApi<JobClass>(params)->then([] { /* code */ })
would make the code even of the library itself much clearer. Type-erased futures can be used as QML-friendly return values instead of job pointers in many places (e.g. in Room
) which otherwise cause troubles (because QML tries to garbage-collect job pointers, not knowing that they are already managed).
Update: needs #479.
https://github.com/simonbrunel/qtpromise looks very promising (pun intended) for the purpose. Unfortunately it's not yet QML-friendly; so the "type-erased futures" part will either have to be done in libQMatrixClient, or PR'ed to QtPromise.
Something related to this issue is that a QPromise class was added in Qt6: https://doc.qt.io/qt-6/qpromise.html
With C++20 there are coroutines available now. QCoro is an interesting Qt implementation of coroutines: https://github.com/danvratil/qcoro. Unfortunately, the compiler support for coroutines is rather poor but it's just a matter of time until it's widely available.