impr: Make sure init tasks always get executed
This commit is contained in:
parent
48b202c56b
commit
71f4f87288
@ -21,6 +21,7 @@ namespace hex::init {
|
||||
std::string name;
|
||||
std::function<bool()> callback;
|
||||
bool async;
|
||||
bool running;
|
||||
};
|
||||
|
||||
enum FrameResult{ Success, Failure, Running };
|
||||
|
@ -27,7 +27,7 @@ namespace hex::init {
|
||||
|
||||
// Add initialization tasks to run
|
||||
TaskManager::init();
|
||||
for (const auto &[name, task, async] : init::getInitTasks())
|
||||
for (const auto &[name, task, async, running] : init::getInitTasks())
|
||||
splashWindow->addStartupTask(name, task, async);
|
||||
|
||||
splashWindow->startStartupTasks();
|
||||
|
@ -60,7 +60,7 @@ namespace hex::init {
|
||||
}
|
||||
|
||||
RequestAddInitTask::subscribe([this](const std::string& name, bool async, const TaskFunction &function){
|
||||
m_tasks.push_back(Task{ name, function, async });
|
||||
m_tasks.push_back(Task{ name, function, async, false });
|
||||
});
|
||||
}
|
||||
|
||||
@ -220,14 +220,17 @@ namespace hex::init {
|
||||
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// Loop over all registered init tasks
|
||||
for (auto it = m_tasks.begin(); it != m_tasks.end(); ++it) {
|
||||
// Construct a new task callback
|
||||
this->createTask(*it);
|
||||
}
|
||||
|
||||
// Check every 100ms if all tasks have run
|
||||
while (true) {
|
||||
// Loop over all registered init tasks
|
||||
for (auto it = m_tasks.begin(); it != m_tasks.end(); ++it) {
|
||||
// Construct a new task callback
|
||||
if (!it->running) {
|
||||
this->createTask(*it);
|
||||
it->running = true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock lock(m_tasksMutex);
|
||||
if (m_completedTaskCount >= m_totalTaskCount)
|
||||
|
@ -251,7 +251,7 @@ namespace hex::init {
|
||||
|
||||
// Run all exit tasks, and print to console
|
||||
void runExitTasks() {
|
||||
for (const auto &[name, task, async] : init::getExitTasks()) {
|
||||
for (const auto &[name, task, async, running] : init::getExitTasks()) {
|
||||
const bool result = task();
|
||||
log::info("Exit task '{0}' finished {1}", name, result ? "successfully" : "unsuccessfully");
|
||||
}
|
||||
@ -259,18 +259,18 @@ namespace hex::init {
|
||||
|
||||
std::vector<Task> getInitTasks() {
|
||||
return {
|
||||
{ "Setting up environment", setupEnvironment, false },
|
||||
{ "Creating directories", createDirectories, false },
|
||||
{ "Loading settings", loadSettings, false },
|
||||
{ "Loading plugins", loadPlugins, false },
|
||||
{ "Setting up environment", setupEnvironment, false, false },
|
||||
{ "Creating directories", createDirectories, false, false },
|
||||
{ "Loading settings", loadSettings, false, false },
|
||||
{ "Loading plugins", loadPlugins, false, false },
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<Task> getExitTasks() {
|
||||
return {
|
||||
{ "Prepare exit", prepareExit, false },
|
||||
{ "Unloading plugins", unloadPlugins, false },
|
||||
{ "Deleting old files", deleteOldFiles, false },
|
||||
{ "Prepare exit", prepareExit, false, false },
|
||||
{ "Unloading plugins", unloadPlugins, false, false },
|
||||
{ "Deleting old files", deleteOldFiles, false, false },
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user