diff --git a/lib/libimhex/include/hex/api/task_manager.hpp b/lib/libimhex/include/hex/api/task_manager.hpp index 562dab0a6..dfc9098d6 100644 --- a/lib/libimhex/include/hex/api/task_manager.hpp +++ b/lib/libimhex/include/hex/api/task_manager.hpp @@ -137,6 +137,15 @@ namespace hex { */ static TaskHolder createTask(const UnlocalizedString &unlocalizedName, u64 maxValue, std::function function); + /** + * @brief Creates a new asynchronous task that gets displayed in the Task Manager in the footer + * @param unlocalizedName Name of the task + * @param maxValue Maximum value of the task + * @param function Function to be executed + * @return A TaskHolder holding a weak reference to the task + */ + static TaskHolder createTask(const UnlocalizedString &unlocalizedName, u64 maxValue, std::function function); + /** * @brief Creates a new asynchronous task that does not get displayed in the Task Manager * @param unlocalizedName Name of the task @@ -145,6 +154,14 @@ namespace hex { */ static TaskHolder createBackgroundTask(const UnlocalizedString &unlocalizedName, std::function function); + /** + * @brief Creates a new asynchronous task that does not get displayed in the Task Manager + * @param unlocalizedName Name of the task + * @param function Function to be executed + * @return A TaskHolder holding a weak reference to the task + */ + static TaskHolder createBackgroundTask(const UnlocalizedString &unlocalizedName, std::function function); + /** * @brief Creates a new synchronous task that will execute the given function at the start of the next frame * @param function Function to be executed diff --git a/lib/libimhex/source/api/task_manager.cpp b/lib/libimhex/source/api/task_manager.cpp index 5c494013a..10e9521b5 100644 --- a/lib/libimhex/source/api/task_manager.cpp +++ b/lib/libimhex/source/api/task_manager.cpp @@ -349,11 +349,29 @@ namespace hex { return createTask(std::move(unlocalizedName), maxValue, false, std::move(function)); } + TaskHolder TaskManager::createTask(const UnlocalizedString &unlocalizedName, u64 maxValue, std::function function) { + log::debug("Creating task {}", unlocalizedName.get()); + return createTask(std::move(unlocalizedName), maxValue, false, + [function = std::move(function)](Task&) { + function(); + } + ); + } + TaskHolder TaskManager::createBackgroundTask(const UnlocalizedString &unlocalizedName, std::function function) { log::debug("Creating background task {}", unlocalizedName.get()); return createTask(std::move(unlocalizedName), 0, true, std::move(function)); } + TaskHolder TaskManager::createBackgroundTask(const UnlocalizedString &unlocalizedName, std::function function) { + log::debug("Creating background task {}", unlocalizedName.get()); + return createTask(std::move(unlocalizedName), 0, true, + [function = std::move(function)](Task&) { + function(); + } + ); + } + void TaskManager::collectGarbage() { { std::scoped_lock lock(s_queueMutex);