fn Batch(comptime Result: type, comptime max_jobs: comptime_int, comptime async_behavior: enum { auto_async, never_async, always_async, _, }) type
Performs multiple async functions in parallel, without heap allocation. Async function frames are managed externally to this abstraction, and passed in via the add
function. Once all the jobs are added, call wait
. This API is not thread-safe. The object must be accessed from one thread at a time, however, it need not be the same thread.
Parameters
Result: type,
The return value for each job. If a job slot was re-used due to maxed out concurrency, then its result value will be overwritten. The values can be accessed with the results
field.
max_jobs: comptime_int,
How many jobs to run in parallel.
async_behavior: enum { auto_async, never_async, always_async, _, },
Controls whether the add
and wait
functions will be async functions.
Functions
fn add(self: *Self, frame: anyframe_type) void
Add a frame to the Batch. If all jobs are in-flight, then this function waits u…
Add a frame to the Batch. If all jobs are in-flight, then this function waits until one completes. This function is not thread-safe. It must be called from one thread at a time, however, it need not be the same thread. TODO: “select” language feature to use the next available slot, rather than awaiting the next index.
fn wait(self: *Self) CollectedResult
Wait for all the jobs to complete. Safe to call any number of times. If `Resul…
Wait for all the jobs to complete. Safe to call any number of times. If
Result
is an error union, this function returns the last error that occurred, if any. Unlike theresults
field, the return value ofwait
will report any error that occurred; hitting max parallelism will not compromise the result. This function is not thread-safe. It must be called from one thread at a time, however, it need not be the same thread.