32 AAsyncHolder() =
default;
34 std::unique_lock lock(mSync);
36 while (!mFutureSet.empty()) {
37 auto l = std::move(mFutureSet.last());
38 mFutureSet.pop_back();
46 while (!mCustomTypeFutures.empty()) {
47 auto l = std::move(mCustomTypeFutures.back());
48 mCustomTypeFutures.pop_back();
59 std::unique_lock lock(mSync);
60 if constexpr (std::is_same_v<void, T>) {
61 auto impl = future.inner().get();
65 std::unique_lock lock(mSync);
66 mFutureSet.removeIf([&](
const AFuture<>& f) {
67 return f.inner().get() == impl;
71 auto uniquePtr = std::make_unique<Future<T>>(future);
72 auto it = mCustomTypeFutures.insert(mCustomTypeFutures.end(), std::move(uniquePtr));
76 future.
onSuccess([
this, it](
const T& result) {
78 std::unique_lock lock(mSync);
80 mCustomTypeFutures.erase(it);
87 std::size_t size()
const {
88 std::unique_lock lock(mSync);
89 return mFutureSet.size();
93 std::unique_lock lock(mSync);
94 if (!mFutureSet.empty()) {
96 auto futureSet = std::move(mFutureSet);
98 futureSet.waitForAll();
100 if (mFutureSet.empty()) {
101 mFutureSet = std::move(futureSet);
103 mFutureSet.insertAll(futureSet);
108 while (!mCustomTypeFutures.empty()) {
109 mCustomTypeFutures.front()->wait(lock);
115 virtual ~IFuture() =
default;
116 virtual void get() = 0;
117 virtual void wait(std::unique_lock<AMutex>& lock) = 0;
118 virtual void cancelAndWait() = 0;
123 struct Future: IFuture {
124 void get()
override {
128 void wait(std::unique_lock<AMutex>& lock)
override {
135 void cancelAndWait()
override {
140 ~Future()
override =
default;
142 Future(
AFuture<T> future) : mFuture(std::move(future)) {}
151 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