libQuotient icon indicating copy to clipboard operation
libQuotient copied to clipboard

Jobs as promises

Open KitsuneRal opened this issue 6 years ago • 3 comments

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.

KitsuneRal avatar Mar 05 '18 09:03 KitsuneRal

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.

KitsuneRal avatar Nov 17 '18 10:11 KitsuneRal

Something related to this issue is that a QPromise class was added in Qt6: https://doc.qt.io/qt-6/qpromise.html

CarlSchwan avatar Dec 19 '20 09:12 CarlSchwan

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.

CarlSchwan avatar Jun 05 '21 12:06 CarlSchwan