libnick 2025.9.1
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
Nickvision::Helpers::CancellationToken Class Reference

A token that can be used to cancel an operation. More...

#include <cancellationtoken.h>

Public Member Functions

 CancellationToken (const std::function< void()> &cancelFunction={}) noexcept
 Constructs a CancellationToken.
 
bool isCancelled () const noexcept
 Gets whether or not the token is cancelled.
 
const std::function< void()> & getCancelFunction () const noexcept
 Gets the cancel function to be called when the token is cancelled.
 
void setCancelFunction (const std::function< void()> &cancelFunction) noexcept
 Sets the cancel function to be called when the token is cancelled.
 
void cancel () noexcept
 Cancels the token.
 
void reset () noexcept
 Resets the token to its initial state.
 
 operator bool () const noexcept
 Converts the token to a boolean.
 

Detailed Description

A token that can be used to cancel an operation.

Constructor & Destructor Documentation

◆ CancellationToken()

Nickvision::Helpers::CancellationToken::CancellationToken ( const std::function< void()> & cancelFunction = {})
noexcept

Constructs a CancellationToken.

Parameters
cancelFunctionA callback function to call when the token is cancelled

Member Function Documentation

◆ cancel()

void Nickvision::Helpers::CancellationToken::cancel ( )
noexcept

Cancels the token.

◆ getCancelFunction()

const std::function< void()> & Nickvision::Helpers::CancellationToken::getCancelFunction ( ) const
noexcept

Gets the cancel function to be called when the token is cancelled.

Returns
The cancel function

◆ isCancelled()

bool Nickvision::Helpers::CancellationToken::isCancelled ( ) const
noexcept

Gets whether or not the token is cancelled.

Returns
True if token is cancelled, else false

◆ operator bool()

Nickvision::Helpers::CancellationToken::operator bool ( ) const
noexcept

Converts the token to a boolean.

Returns
True if token is cancelled, else false

◆ reset()

void Nickvision::Helpers::CancellationToken::reset ( )
noexcept

Resets the token to its initial state.

Removes the cancel function and sets the cancelled state to false.

◆ setCancelFunction()

void Nickvision::Helpers::CancellationToken::setCancelFunction ( const std::function< void()> & cancelFunction)
noexcept

Sets the cancel function to be called when the token is cancelled.

Parameters
cancelFunctionThe cancel function

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