libnick 2025.9.1
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
cancellationtoken.h
Go to the documentation of this file.
1
22
23#ifndef CANCELLATIONTOKEN_H
24#define CANCELLATIONTOKEN_H
25
26#include <functional>
27#include <mutex>
28
30{
35 {
36 public:
41 CancellationToken(const std::function<void()>& cancelFunction = {}) noexcept;
46 bool isCancelled() const noexcept;
51 const std::function<void()>& getCancelFunction() const noexcept;
56 void setCancelFunction(const std::function<void()>& cancelFunction) noexcept;
60 void cancel() noexcept;
65 void reset() noexcept;
70 operator bool() const noexcept;
71
72 private:
73 mutable std::mutex m_mutex;
74 bool m_cancelled;
75 std::function<void()> m_cancelFunction;
76 };
77}
78
79#endif //CANCELLATIONTOKEN_H
CancellationToken(const std::function< void()> &cancelFunction={}) noexcept
Constructs a CancellationToken.
void cancel() noexcept
Cancels the token.
const std::function< void()> & getCancelFunction() const noexcept
Gets the cancel function to be called when the token is cancelled.
void reset() noexcept
Resets the token to its initial state.
bool isCancelled() const noexcept
Gets whether or not the token is cancelled.
void setCancelFunction(const std::function< void()> &cancelFunction) noexcept
Sets the cancel function to be called when the token is cancelled.
Definition cancellationtoken.h:30