-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Labels
Description
Hey there,
would it be possible to add API or an example on how to wrap promises of different types? E.g. to handle a scenario such as:
- do A returning a_t
- do B returning b_t
- await for A and B then do C taking a_t and b_t.
Ideally something like this:
auto a = qPromise(QtConcurrent::run([](){return QStringLiteral("foo");}));
auto b = qPromise(QtConcurrent::run([](){return 42;}));
qPromiseAll(a, b).then([](const QString &str, int num) {});
I believe one could handle this manually by building a promise that stores a tuple of return args (here QString and int) as well as a counter to check how many of the child promises have been fulfilled. Then when a child promise is fulfilled store its return type and decrement the counter, and if that reaches zero resolve the parent promise? And if any child promise gets rejected, also reject the parent promise?