Line data Source code
1 : // 2 : // Copyright 2024 OpenModelViewer Authors 3 : // 4 : // Licensed under the Apache License, Version 2.0 (the "License"); 5 : // you may not use this file except in compliance with the License. 6 : // You may obtain a copy of the License at 7 : // 8 : // http://www.apache.org/licenses/LICENSE-2.0 9 : // 10 : // Unless required by applicable law or agreed to in writing, software 11 : // distributed under the License is distributed on an "AS IS" BASIS, 12 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 : // See the License for the specific language governing permissions and 14 : // limitations under the License. 15 : // 16 : 17 : #pragma once 18 : 19 : #include <exception> 20 : 21 : namespace openmodelviewer::core::async 22 : { 23 : /** 24 : * @brief Interface for type-erased access to asynchronous task state. 25 : * 26 : * This interface allows TaskScheduler and other systems to track completion 27 : * and error status of a task without knowing its result type. 28 : * 29 : * Implementations typically wrap a TaskData<T> instance. 30 : */ 31 : class ITaskData 32 : { 33 : public: 34 101 : virtual ~ITaskData() = default; 35 : 36 : /** 37 : * @brief Indicates whether the task has completed. 38 : * @return true if the task has finished (success or failure). 39 : */ 40 : virtual bool completed() const noexcept = 0; 41 : 42 : /** 43 : * @brief Indicates whether the task resulted in an exception. 44 : * @return true if the task threw an exception during execution. 45 : */ 46 : virtual bool errored() const noexcept = 0; 47 : 48 : /** 49 : * @brief Returns the stored exception pointer, if any. 50 : * @return std::exception_ptr representing the error, or nullptr if none. 51 : */ 52 : virtual std::exception_ptr exception() const noexcept = 0; 53 : 54 : virtual bool hasCallback() const noexcept = 0; 55 : virtual void invokeCallback() = 0; 56 : }; 57 : } // namespace openmodelviewer::core::async