MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Parallel::AsyncGroup< T > Class Template Reference

Owns a set of in-flight std::async futures on behalf of a subsystem. More...

#include <AsyncGroup.hpp>

+ Inheritance diagram for MayaFlux::Parallel::AsyncGroup< T >:
+ Collaboration diagram for MayaFlux::Parallel::AsyncGroup< T >:

Public Types

using ExceptionHandler = std::function< void(std::exception_ptr)>
 Exception policy invoked once per exception observed from a submitted future's get().
 

Public Member Functions

size_t approx_pending () const noexcept
 Approximate count of futures not yet reclaimed.
 
 AsyncGroup ()=default
 
 AsyncGroup (AsyncGroup &&)=delete
 
 AsyncGroup (const AsyncGroup &)=delete
 
 AsyncGroup (ExceptionHandler handler)
 Construct with an explicit exception policy.
 
void drain ()
 Blocks until every currently submitted future completes.
 
AsyncGroup & operator= (AsyncGroup &&)=delete
 
AsyncGroup & operator= (const AsyncGroup &)=delete
 
void submit (std::future< T > fut)
 Retains fut and opportunistically reclaims completed work.
 
std::vector< std::exception_ptr > take_errors ()
 Returns and clears exceptions accumulated with no handler set.
 
 ~AsyncGroup ()
 Drains all in-flight work before destruction.
 

Private Member Functions

void finish (std::future< T > &f)
 
void report (std::exception_ptr ep)
 

Private Attributes

Memory::SweepList< std::exception_ptr > m_errors
 
ExceptionHandler m_handler
 
Memory::SweepList< std::future< T > > m_tasks
 

Detailed Description

template<typename T = void>
class MayaFlux::Parallel::AsyncGroup< T >

Owns a set of in-flight std::async futures on behalf of a subsystem.

Centralizes the future-ownership mechanics that subsystems such as IOManager and Yantra::ComputeMatrix each implemented independently: submit work, retain the future past the initiating call, prune completed work opportunistically, and block on everything remaining at teardown.

AsyncGroup is not a thread pool or scheduler. It does not launch work itself; callers still call std::async (or any callable returning std::future<T>) and hand the future to submit(). It does not reuse threads, size a queue, or impose priorities or affinity. It only answers "who owns this future until it's done, and who notices if it failed."

Storage is MayaFlux::Memory::SweepList, so submission, opportunistic pruning, and drain are all lock-free and unbounded; see SweepList.hpp for the concurrency shape.

Exceptions from a submitted task are never silently discarded. Each one is reported to a policy: a caller-supplied handler if one was set at construction, or, absent a handler, retained internally and returned by take_errors() so a caller can inspect them explicitly.

Template Parameters
TResult type of the tracked futures. Use AsyncGroup<void> for completion-only tracking, AsyncGroup<bool> for a group whose tasks report success/failure, and so on.
[](std::exception_ptr ep) {
try { std::rethrow_exception(ep); }
catch (const std::exception& e) { MF_ERROR(..., "save failed: {}", e.what()); }
});
save_tasks.submit(std::async(std::launch::async, [] { return write_file(); }));
// Later, at teardown:
save_tasks.drain();
#define MF_ERROR(comp, ctx,...)
void submit(std::future< T > fut)
Retains fut and opportunistically reclaims completed work.
Owns a set of in-flight std::async futures on behalf of a subsystem.

Definition at line 51 of file AsyncGroup.hpp.


The documentation for this class was generated from the following file: