libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AlgAudio::Sync Class Reference

#include <LateReturn.hpp>

Public Member Functions

 Sync (int count)
 
void Trigger () const
 
void WhenAll (std::function< void()> func) const
 

Detailed Description

Sync is a helper class that makes it easy to wait for multiple LateReplies to arrive.

Sync maintains an internal counter that is initially set to some value. Each finished LateReturn decrements the counter, when it reaches zero the stored function (set by WhenAll) is called.

Example usage:

Sync s(3);
PerformLongActionA(args1).ThenSync(s);
PerformLongActionB(args2).ThenSync(s);
PerformLongActionC(args3).ThenSync(s);
s.WhenAll([](){
std::cout << "Done!" << std::endl;
});

Sync instances are shared; when copy-assigning or copy-constructing a sync, it will use the same counter. Therefore, when using Sync in lambda functions, it is recommended to pass Sync instances by-value.

Constructor & Destructor Documentation

AlgAudio::Sync::Sync ( int  count)

Constructs a new instance of a Sync.

Parameters
countThe number of LateReplies to wait for.

Member Function Documentation

void AlgAudio::Sync::Trigger ( ) const

Decrements the internal counter, and, potentially, invokes the stored function.

void AlgAudio::Sync::WhenAll ( std::function< void()>  func) const

Sets the function that is supposed to happen when the counter gets down to zero.

Parameters
funcThe parram-less function to call.

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