Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Creating a completed Deferred is very heavy #21

Closed
vpicaver opened this issue Nov 4, 2019 · 1 comment
Closed

Creating a completed Deferred is very heavy #21

vpicaver opened this issue Nov 4, 2019 · 1 comment

Comments

@vpicaver
Copy link
Contributor

vpicaver commented Nov 4, 2019

Chaining asyncfuture is useful to chain QFuture's together. Sometimes at the begin of the chain, it's useful to have completed QFuture that come from a fixed value. To achieve this with asyncfuture, a programmer needs to use deferred() and then complete it with deferred::complete(). Although this works, deferred creates a Deferred object and a that holds a DeferredFuture. A DeferredFuture is a fairly heavy weight object since inherits QObject and hold a mutex. A DeferrerFuture is usually stored as a shared object and require reference counting.

To reduce this overhead for the specific job having a QFuture that's automatically complete, I propose having a QFuture<void> finished() and QFuture<T> finished<T>() functions.

They would be implement as the following:

inline QFuture<void> finished() {
   QFutureInterface<void> fi;
   fi.reportFinished();
   return QFuture<void>(&fi);
}

template <typename T> QFuture<T> finished(const T &val) {
   QFutureInterface<T> fi;
   fi.reportFinished(&val);
   return QFuture<T>(&fi);
}
@vpicaver vpicaver changed the title Creating a completed is Deferred very heavy Creating a completed Deferred very heavy Nov 4, 2019
@vpicaver vpicaver changed the title Creating a completed Deferred very heavy Creating a completed Deferred is very heavy Nov 4, 2019
vpicaver pushed a commit to vpicaver/asyncfuture that referenced this issue Nov 4, 2019
vpicaver pushed a commit to vpicaver/asyncfuture that referenced this issue Nov 4, 2019
@remster
Copy link

remster commented Feb 17, 2020

Ack! This is needed.

@vpicaver vpicaver closed this as completed Mar 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants