You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
I have a result that depends on an arbitrary number of inputs, where arbitrary means: possibly also 0. Each of the inputs can either be immediately available or require delegation to a thread. Now I use AsyncFuture::Combinator to detect when all the results are ready.
My first attempt looked like this:
[...]
auto combiner = AsyncFuture::combine();
QVector<QFuture<Result>> results;
for(auto item: items) {
auto future = getCachedResultOrCompute(item);
results << future;
combiner << future;
}
return combiner.subscribe([results]() {
// do something with the results...
}).future();
This approach has one problem though: If items is empty, the callback given to subscribe will never get called. So, it'd be convenient if it were possible to write something like the following wrapper to subscribe on Combinator:
This requires a method isEmpty (or whatever you'd like to call it) on Combinator, allowing the client to query whether or not there is already a QFuture on Combinator. As far as I can see, it is easily implented by adding the following code to Combinator: bool isEmpty() const { return combinedFuture->count == 0; }
The text was updated successfully, but these errors were encountered:
I would suggest an alternative approach. In the latest master branch, I have make the Combinator to support to set progressValue , progressMaximum value.
auto d1 = timeout(50);
auto d2 = timeout(60);
auto d3 = timeout(30);
auto combinator = combine();
combinator << d1 << d2 << d3;
auto future = combinator.future();
QCOMPARE(future.progressValue(), 0);
QCOMPARE(future.progressMaximum(), 3);
await(future);
QCOMPARE(future.progressValue(), 3);
QCOMPARE(future.progressMaximum(), 3);
So that you could query the no. of added future by using combinator.future().progressMaximum()
Okay, this looks nice. So QFutureInterface guarantees progressMaximum() to return zero before any call to setProgressRange has been made?
To make this expectation explicit, I'd suggest we should add another
QCOMPARE(future.progressMaximum(), 0);
just after the intialisation of combinator to the test.
My motivation is the following use case:
I have a result that depends on an arbitrary number of inputs, where arbitrary means: possibly also 0. Each of the inputs can either be immediately available or require delegation to a thread. Now I use
AsyncFuture::Combinator
to detect when all the results are ready.My first attempt looked like this:
This approach has one problem though: If
items
is empty, the callback given tosubscribe
will never get called. So, it'd be convenient if it were possible to write something like the following wrapper tosubscribe
onCombinator
:This requires a method
isEmpty
(or whatever you'd like to call it) on Combinator, allowing the client to query whether or not there is already aQFuture
on Combinator. As far as I can see, it is easily implented by adding the following code toCombinator
:bool isEmpty() const { return combinedFuture->count == 0; }
The text was updated successfully, but these errors were encountered: