Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
asyncpp::scope_guard< TFunction > Class Template Reference

Execute a callback function when this scope gets destroyed. More...

#include <asyncpp/scope_guard.h>

Public Member Functions

 scope_guard (TFunction func, bool engaged=true) noexcept(std::is_nothrow_move_constructible_v< TFunction >)
 Construct a new scope guard.
 
 scope_guard (const scope_guard &)=delete
 
scope_guardoperator= (const scope_guard &)=delete
 
 ~scope_guard ()
 Destructor.
 
void disengage () noexcept
 Disengage the guard, making sure the callback is not executed on destruction.
 
void engage () noexcept
 Engage the guard, making sure the callback is executed on destruction.
 
bool is_engaged () const noexcept
 Check if the guard is engaged.
 
TFunction & function () noexcept
 Get a reference to the contained function.
 
const TFunction & function () const noexcept
 Get a const reference to the contained function.
 

Detailed Description

template<typename TFunction>
class asyncpp::scope_guard< TFunction >

Execute a callback function when this scope gets destroyed.

Note
Because the callback is executed in the destructor it is required to be marked noexcept.
Template Parameters
TFunctionType of the callback function

Constructor & Destructor Documentation

◆ scope_guard()

template<typename TFunction >
asyncpp::scope_guard< TFunction >::scope_guard ( TFunction func,
bool engaged = true )
inlineexplicitnoexcept

Construct a new scope guard.

Parameters
funcThe function to invoke
engagedtrue if the guard is engaged right away.

Member Function Documentation

◆ is_engaged()

template<typename TFunction >
bool asyncpp::scope_guard< TFunction >::is_engaged ( ) const
inlinenoexcept

Check if the guard is engaged.

Returns
true if the callback will execute on destruction, false if not.

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