Taskwork

Efficient multi-threaded task scheduler using generic re-usable WebWorkers.
Taskwork
is a task scheduler that is able to delegate tasks to WebWorkers. These WebWorkers are special in the sense that they are able to execute and return the results from of arbitrary tasks. At the start of the application a static amount of threads are spawned, are re-used and are kept alive throughout the lifetime of the application. This has the advantage of only paying the spawn-cost of WebWorkers (~45 ms
) and the overhead of spawning only once.
Another feature of Taskwork
is the ability to schedule a task with a certain priority. By automatically sorting the task queue based on priority we can make sure that tasks with the highest priority are executed first. This is important because the goal is to stay within the frameTarget (usually 60 fps)
budget. Taskwork
internally checks wether there is enough time left in the frame to run a task and automatically defers it to the next frame if not.
Status
UNSTABLE
Installation
Make sure you have Node.js installed.
$ npm install taskwork
Usage
import { Priorities, Scheduler } from 'taskwork';
const getUser = async (username: string) => {
const url = `https://api.github.com/users/${username}`;
const res = await fetch(url);
const profile = await res.json();
return profile.name;
};
const scheduler = new Scheduler({
frameTarget?: number;
threadCount?: number;
});
async () => {
await Promise.all([
scheduler.addTask(Priorities.LowPriority, getUser, ['microsoft']),
scheduler.addTask(Priorities.ImmediatePriority, getUser, [
'timvanscherpenzeel',
]),
]).then((response: any) => {
console.log(response);
});
const taskAp = scheduler.addTask(Priorities.LowPriority, getUser, [
'microsoft',
]);
const taskBp = scheduler.addTask(Priorities.ImmediatePriority, getUser, [
'timvanscherpenzeel',
]);
const taskA = await taskAp;
const taskB = await taskBp;
console.log(taskA, taskB);
};
Licence
My work is released under the MIT license.