[Interest] Guarantee on finished emission with multiple QFutureWatchers?

Elvis Stansvik elvstone at gmail.com
Thu Oct 18 17:02:10 CEST 2018


Bah, title of the mail should have been "Guarantee on finished
emission _order_ ..." or course.

Elvis
Den tors 18 okt. 2018 kl 16:53 skrev Elvis Stansvik <elvstone at gmail.com>:
>
> Hi all,
>
> Is there any guarantee on the order in which the
> QFutureWatcher::finished signal will be emitted when multiple
> QFutureWatchers are hooked up to the same QFuture?
>
> When the QFuture finishes, will finished be emitted by the
> QFutureWatchers in the order in which setFuture were called upon them?
> Or is there no guarantee?
>
> I'm thinking of a use case like (rough pseudo code):
>
> QFuture CachingReader::readAsync(...) {
>     if (result is available in cache) {
>         QFutureInterface interface;
>         interface.reportFinished(result from cache);
>         return QFuture(interface);
>     }
>
>     future = QtConcurrent::run(readStuff, ...);
>     watcher = QFutureWatcher();
>     connect(watcher, finished, [this, future]() {
>         // store future.result() in cache
>     });
>     watcher.setFuture(future);
>
>     return future;
> }
>
> In this case, I'd really like the QFutureWatcher set up internally by
> the function to be the one that fires first. It is guaranteed to be
> the first one that calls QFutureWatcher::setFuture(..) with that
> QFuture as parameter, but I'm not sure if that's any guarantee here?
>
> Thanks in advance,
> Elvis



More information about the Interest mailing list