46 lines
992 B
C++
Executable File
46 lines
992 B
C++
Executable File
// License: Modified MIT (NON-AI)
|
|
// See the LICENSE file in the root directory for license information.
|
|
// Copyright 2026 Timothy Prepscius
|
|
|
|
#pragma once
|
|
|
|
#include "Future.hpp"
|
|
#include "weak_future_consume.hpp"
|
|
#include <utility>
|
|
|
|
namespace tjp {
|
|
namespace core {
|
|
|
|
template<typename F0, typename FutureGenerator>
|
|
auto after(F0 &&f0, FutureGenerator &&next)
|
|
{
|
|
typedef decltype(f0.get()) R0;
|
|
typedef decltype(next(f0)) F1_Ref;
|
|
typedef typename std::remove_reference<F1_Ref>::type F1;
|
|
typedef decltype(std::declval<F1>().get()) R1_Ref;
|
|
typedef typename std::remove_reference<R1_Ref>::type R1;
|
|
|
|
Promise<R1> p;
|
|
auto p_ = weak(p.shared);
|
|
|
|
auto swizzle = f0.then([p_, next](auto &&f0) {
|
|
return
|
|
future_with([&]() { return next(f0); })
|
|
.then([p_](auto &&f1) {
|
|
weak_future_consume(
|
|
p_,
|
|
[](auto &&f1) { return f1.get(); },
|
|
f1
|
|
);
|
|
});
|
|
|
|
});
|
|
|
|
return p.get_future().then([swizzle](auto &&f1) {
|
|
return f1.get();
|
|
});
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace
|