mirror of
https://github.com/wukko/cobalt.git
synced 2025-04-29 22:14:26 +02:00
39 lines
963 B
TypeScript
39 lines
963 B
TypeScript
import { readable, type Updater } from "svelte/store";
|
|
|
|
import type { CobaltWorkerProgress } from "$lib/types/workers";
|
|
import type { CobaltCurrentTasks, CobaltCurrentTaskItem } from "$lib/types/task-manager";
|
|
|
|
let update: (_: Updater<CobaltCurrentTasks>) => void;
|
|
|
|
export const currentTasks = readable<CobaltCurrentTasks>(
|
|
{},
|
|
(_, _update) => { update = _update }
|
|
);
|
|
|
|
export function addWorkerToQueue(workerId: string, item: CobaltCurrentTaskItem) {
|
|
update(tasks => {
|
|
tasks[workerId] = item;
|
|
return tasks;
|
|
});
|
|
}
|
|
|
|
export function removeWorkerFromQueue(id: string) {
|
|
update(tasks => {
|
|
delete tasks[id];
|
|
return tasks;
|
|
});
|
|
}
|
|
|
|
export function updateWorkerProgress(workerId: string, progress: CobaltWorkerProgress) {
|
|
update(allTasks => {
|
|
allTasks[workerId].progress = progress;
|
|
return allTasks;
|
|
});
|
|
}
|
|
|
|
export function clearCurrentTasks() {
|
|
update(() => {
|
|
return {};
|
|
});
|
|
}
|