A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
parallel.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//
18// Licensed under the Apache License, Version 2.0 (the "License");
19// you may not use this file except in compliance with the License.
20// You may obtain a copy of the License at
21//
22// http://www.apache.org/licenses/LICENSE-2.0
23//
24// Unless required by applicable law or agreed to in writing, software
25// distributed under the License is distributed on an "AS IS" BASIS,
26// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27// See the License for the specific language governing permissions and
28// limitations under the License.
29
30#ifndef A11_CONCURRENCY_PARALLEL_H_
31#define A11_CONCURRENCY_PARALLEL_H_
32
33#include <cstddef>
34#include <utility>
35#include <vector>
36
37#include <absl/functional/any_invocable.h>
38#include <absl/status/status.h>
39#include <absl/status/statusor.h>
40#include <absl/time/time.h>
41
44#include "thread/concurrency.h"
45
48
49namespace a11 {
50
55template <typename T>
56std::vector<absl::StatusOr<T>> AwaitAll(
57 const std::vector<Future<T>>& futures,
58 absl::Time deadline = absl::InfiniteFuture()) {
59 std::vector<absl::StatusOr<T>> results;
60 results.reserve(futures.size());
61 for (const Future<T>& future : futures) {
62 results.push_back(future.Await(deadline));
63 }
64 return results;
65}
66
67// Runs each callable on its own fiber and waits for all of them. `stack_size`
68// sets each fiber's stack.
75absl::Status RunAllToCompletion(
76 std::vector<absl::AnyInvocable<absl::Status() &&>> work,
77 size_t stack_size = 256 * 1024);
78
79} // namespace a11
80
81#endif // A11_CONCURRENCY_PARALLEL_H_
Shared handle to one asynchronous result.
Definition future.h:126
Completion values used by every asynchronous A11 operation.
Definition action.cc:63
std::vector< absl::StatusOr< T > > AwaitAll(const std::vector< Future< T > > &futures, absl::Time deadline=absl::InfiniteFuture())
Awaits futures that are already running, and returns every result.
Definition parallel.h:56
absl::Status RunAllToCompletion(std::vector< absl::AnyInvocable< absl::Status() && > > work, size_t stack_size)
Runs each callable on its own fiber and waits for all of them.
Definition parallel.cc:30