require("../../_virtual/_rolldown/runtime.js");
const require_defineProperty = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js");
const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
let _pisell_utils = require("@pisell/utils");
//#region src/utils/tasks/index.ts
/**
* 任务管理器
* 可以添加任务到数组
* 每次调用runTask, 取第一个执行，执行完毕后删除此任务
*/
var TasksManager = class {
	constructor() {
		require_defineProperty._defineProperty(this, "tasks", []);
		this.tasks = [];
	}
	add(code) {
		this.tasks.push({
			id: (0, _pisell_utils.getUniqueId)(),
			code
		});
	}
	addTasks(codes) {
		codes.forEach((code) => {
			this.add(code);
		});
	}
	getTasks() {
		return this.tasks;
	}
	run() {
		var _this = this;
		return require_asyncToGenerator._asyncToGenerator(function* () {
			const task = _this.tasks.shift();
			if (!task) return;
			yield task.code(_this);
			_this.delete(task.id);
		})();
	}
	delete(id) {
		this.tasks = this.tasks.filter((t) => t.id !== id);
	}
	clear() {
		this.tasks = [];
	}
};
//#endregion
exports.TasksManager = TasksManager;
