33 AAsyncHolder() =
default;
35 std::unique_lock lock(mSync);
37 while (!mFutureSet.empty()) {
38 auto l = std::move(mFutureSet.last());
39 mFutureSet.pop_back();
47 while (!mCustomTypeFutures.empty()) {
48 auto l = std::move(mCustomTypeFutures.back());
49 mCustomTypeFutures.pop_back();
60 std::unique_lock lock(mSync);
61 if constexpr (std::is_same_v<void, T>) {
62 auto impl = future.inner().get();
66 std::unique_lock lock(mSync);
67 mFutureSet.removeIf([&](
const AFuture<>& f) {
68 return f.inner().get() == impl;
72 auto uniquePtr = std::make_unique<Future<T>>(future);
73 auto it = mCustomTypeFutures.insert(mCustomTypeFutures.end(), std::move(uniquePtr));
77 future.
onSuccess([
this, it](
const T& result) {
79 std::unique_lock lock(mSync);
81 mCustomTypeFutures.erase(it);
88 std::size_t size()
const {
89 std::unique_lock lock(mSync);
90 return mFutureSet.size();
94 std::unique_lock lock(mSync);
95 if (!mFutureSet.empty()) {
97 auto futureSet = std::move(mFutureSet);
99 futureSet.waitForAll();
101 if (mFutureSet.empty()) {
102 mFutureSet = std::move(futureSet);
104 mFutureSet.insertAll(futureSet);
109 while (!mCustomTypeFutures.empty()) {
110 mCustomTypeFutures.front()->wait(lock);
116 virtual ~IFuture() =
default;
117 virtual void get() = 0;
118 virtual void wait(std::unique_lock<AMutex>& lock) = 0;
119 virtual void cancelAndWait() = 0;
124 struct Future: IFuture {
125 void get()
override {
129 void wait(std::unique_lock<AMutex>& lock)
override {
136 void cancelAndWait()
override {
141 ~Future()
override =
default;
143 Future(
AFuture<T> future) : mFuture(std::move(future)) {}
152 std::list<_unique<IFuture>> mCustomTypeFutures;
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition Assert.h:74