/*
 * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#include <algorithm>

#include "task.hpp"

namespace nostalgia::studio {

void TaskRunner::update(core::Context *ctx) noexcept {
	oxIgnoreError(m_tasks.erase(std::remove_if(m_tasks.begin(), m_tasks.end(), [&](auto &t) {
		const auto done = t->update(ctx) == TaskState::Done;
		if (done) {
			t->finished.emit();
		}
		return done;
	})));
}

void TaskRunner::add(Task *task) noexcept {
	m_tasks.emplace_back(task);
}

}
