Comments (2)
Hi @wjHunter!
I would move reply
out of the QPromise constructor and use finally
(always called) to delete the reply (thus would not rely on QNetworkRequest::AutoDeleteReplyOnFinishAttribute
). I would also probably use QtPromise::connect
instead of the QPromise constructor. For example:
QtPromise::QPromise<QByteArray> request(QNetworkAccessManager& network, const QUrl& endpoint)
{
auto reply = network.get(QNetworkRequest{endpoint});
return QtPromise::connect(reply, &QNetworkReply::finished)
.timeout(250)
.then([reply]() {
if (reply->error() != QNetworkReply::NoError) {
throw reply->error();
}
return reply->readAll();
})
.finally([reply]() {
reply->deleteLater();
});
}
from qtpromise.
Thank you for the very quick reply
from qtpromise.
Related Issues (20)
- want to unpack and assign qtpromise value to a C++ private member HOT 1
- using QtPromise from QtConcurrent background task HOT 15
- Awaiting QtPromises of different type HOT 1
- Support for promise cancellation HOT 7
- How can I flatten nested promises? HOT 3
- promise handler does not forward unique_ptr HOT 7
- Support for class member functions in then() HOT 5
- Question about xxx and xxxBase classes
- When using QtPromise::all a following fail and finally are not called HOT 3
- Question about executing context HOT 16
- Qt 6 name conflict HOT 11
- "Getting Started" section for CMake could be improved HOT 1
- invalid use of incomplete type: QPromiseConversionException in qpromise_p.h HOT 5
- API question: Is there value_or(...) equivalent? HOT 7
- The QObject::deleteLater() in .then doesn't work. HOT 3
- QPromise<QString>::reject can't work in the chain, console only print "foo", i wish it is "foo" and "l2-reject l1-reject" HOT 2
- Invalid thread pointer crash in qtpromise_defer() HOT 10
- Release Candidate for v0.7.0 HOT 1
- Different .then behavior than expected HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qtpromise.