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);
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);
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;
Holds a set of futures keeping them valid.
Definition: AAsyncHolder.h:30
Manages multiple futures.
Definition: AThreadPool.h:175
Represents a value that will be available at some point in the future.
Definition: AFuture.h:620
const AFuture & onSuccess(Callback &&callback) const noexcept
Add onSuccess callback to the future.
Definition: AFuture.h:698
void removeIf(Predicate &&predicate) noexcept
Definition: AVector.h:333
StoredType & last() noexcept
Definition: AVector.h:256
iterator insertAll(const OtherContainer &c) noexcept
Definition: AVector.h:60
#define AUI_ASSERT(condition)
Asserts that the passed condition evaluates to true.
Definition: Assert.h:55
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition: Assert.h:74
Basic syscall-based synchronization primitive.
Definition: AMutex.h:33