C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::experimental::ListFutureProvider< FutureType, Lock > Class Template Reference

Overview

template<typename FutureType, typename Lock = sync::InterruptSpinLock>
class pw::async2::experimental::ListFutureProvider< FutureType, Lock >

Manages a list of futures for a single asynchronous operation.

An asynchronous operation that vends futures to multiple callers can use a ListFutureProvider to track them. This class can be used with any future that derives from a listable type like ListableFutureWithWaker. The provider and its futures automatically handle list updates during moves.

All operations on the list are thread-safe, allowing futures to be modified from outside of an async context (for example, to complete a future on an external signal). The type of lock used is configurable, though it is important to understand that the lock will be acquired within the asynchronous dispatcher's thread. Therefore, it is strongly recommended to avoid long-blocking locks such as mutexes as they will stall other tasks.

The default lock is a pw::sync::InterruptSpinLock, which is a safe choice for use within an async context. If it is certain that futures in the list will only be managed from within an async context (for example, between different async tasks), a no-op lock can be used for efficiency.

The future list is FIFO: Pop returns futures in the order they were added.

When a future in the list is destroyed, it safely removes itself. The provider is not notified of this event.

Public Member Functions

 ListFutureProvider (const ListFutureProvider &)=delete
 
ListFutureProvideroperator= (const ListFutureProvider &)=delete
 
void Push (FutureType &future)
 Adds a future to the end of the list.
 
FutureType & Pop ()
 
bool empty ()
 Returns true if there are no futures listed.
 
Lock & lock ()
 Provides access to the list's internal lock.
 

Friends

template<typename , typename >
class ListableFutureWithWaker
 

Member Function Documentation

◆ Pop()

template<typename FutureType , typename Lock = sync::InterruptSpinLock>
FutureType & pw::async2::experimental::ListFutureProvider< FutureType, Lock >::Pop ( )
inline

Removes and returns the first future from the list.

Triggers an assertion if the list is empty.


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