Skip to content

Commit

Permalink
Add utility used for building QPromise from Qt signals
Browse files Browse the repository at this point in the history
  • Loading branch information
pwuertz committed Mar 19, 2018
1 parent d279fb4 commit 09a709e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/qtpromise/qpromisehelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// QtPromise
#include "qpromise_p.h"
#include <memory>

namespace QtPromise {

Expand Down Expand Up @@ -38,6 +39,29 @@ static inline QPromise<void> qPromiseAll(const Sequence<QPromise<void>, Args...>
return QPromise<void>::all(promises);
}

class ConnectionGuard {
public:
static std::shared_ptr<ConnectionGuard> create() {
return std::shared_ptr<ConnectionGuard>(new ConnectionGuard);
}
void operator<<(QMetaObject::Connection &&other) {
connections.emplace_back(std::move(other));
}
void disconnect() {
for (const auto& connection: connections)
QObject::disconnect(connection);
connections.clear();
}
~ConnectionGuard() {
disconnect();
}
protected:
std::vector<QMetaObject::Connection> connections;
ConnectionGuard() = default;
ConnectionGuard(const ConnectionGuard&) = delete;
void operator=(const ConnectionGuard&) = delete;
};

} // namespace QtPromise

#endif // QTPROMISE_QPROMISEHELPERS_H

0 comments on commit 09a709e

Please # to comment.