5#include <albert/export.h>
8namespace albert::detail
12class ALBERT_EXPORT ScopedFuture
15 explicit ScopedFuture(QFuture<T> f) : future_opt(std::move(f)) {}
16 ~ScopedFuture() { waitForFinished(); }
18 void waitForFinished()
20 if (future_opt && !future_opt->isFinished())
21 future_opt->waitForFinished();
24 ScopedFuture(
const ScopedFuture &) =
delete;
25 ScopedFuture(ScopedFuture &&other) noexcept
26 : future_opt(std::move(other.future_opt))
27 { other.future_opt.reset(); };
29 ScopedFuture &operator=(
const ScopedFuture &) =
delete;
30 ScopedFuture &operator=(ScopedFuture &&other)
noexcept
33 future_opt = std::move(other.future_opt);
34 other.future_opt.reset();
38 auto&& operator*(
this auto&& self) {
39 return *std::forward<decltype(self)>(self).future_opt;
42 auto* operator->(
this auto&& self) {
43 return &*std::forward<decltype(self)>(self).future_opt;
46 auto&& get(
this auto&& self) {
47 return *std::forward<decltype(self)>(self).future_opt;
49 void reset() { future_opt.reset(); }
52 std::optional<QFuture<T>> future_opt;