diff --git a/olp-cpp-sdk-core/include/olp/core/client/CancellationToken.h b/olp-cpp-sdk-core/include/olp/core/client/CancellationToken.h index e7ffb39c3..348070bf7 100644 --- a/olp-cpp-sdk-core/include/olp/core/client/CancellationToken.h +++ b/olp-cpp-sdk-core/include/olp/core/client/CancellationToken.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ class CORE_API CancellationToken { void Cancel() const; private: - CancelFuncType func_; + mutable CancelFuncType func_; }; } // namespace client diff --git a/olp-cpp-sdk-core/src/client/CancellationToken.cpp b/olp-cpp-sdk-core/src/client/CancellationToken.cpp index 5afb3bce6..912da49cc 100644 --- a/olp-cpp-sdk-core/src/client/CancellationToken.cpp +++ b/olp-cpp-sdk-core/src/client/CancellationToken.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,10 @@ CancellationToken::CancellationToken(CancelFuncType func) : func_(std::move(func)) {} void CancellationToken::Cancel() const { - if (func_) { - func_(); + CancelFuncType func; + std::swap(func_, func); + if (func) { + func(); } }