95 return makeFuture<Unit>(std::runtime_error(
"Cycle in FutureDAG graph"));
97 std::vector<Handle> rootNodes;
98 std::vector<Handle> leafNodes;
99 for (
Handle handle = 0; handle <
nodes.size(); handle++) {
100 if (
nodes[handle].dependencies.empty()) {
101 rootNodes.push_back(handle);
103 if (!
nodes[handle].hasDependents) {
104 leafNodes.push_back(handle);
108 auto sinkHandle =
add([] {
return Future<Unit>(); });
109 for (
auto handle : leafNodes) {
113 auto sourceHandle =
add(
nullptr);
114 for (
auto handle : rootNodes) {
118 for (
Handle handle = 0; handle <
nodes.size() - 1; handle++) {
119 std::vector<Future<Unit>> dependencies;
120 for (
auto depHandle :
nodes[handle].dependencies) {
121 dependencies.push_back(
nodes[depHandle].promise.getFuture());
126 .thenValue([
this, handle](std::vector<Unit>&&) {
127 nodes[handle].func().then([
this, handle](Try<Unit>&&
t) {
131 .onError([
this, handle](exception_wrapper ew) {
136 nodes[sourceHandle].promise.setValue();
137 return nodes[sinkHandle].promise.getFuture().thenValue(
138 [that = shared_from_this(), sourceHandle, sinkHandle](Unit) {
139 that->clean_state(sourceHandle, sinkHandle);
Handle add(FutureFunc func, Executor *executor=nullptr)
constexpr detail::Map< Move > move
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
void dependency(Handle a, Handle b)
std::vector< Node > nodes
Future< std::vector< typename std::iterator_traits< InputIterator >::value_type::value_type > > collect(InputIterator first, InputIterator last)