
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Efficient multi-threaded task scheduler for the browser 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 arbitrary tasks send to them. At the start of the application a fixed amount of threads are spawned and re-used throughout the lifetime of the application. This has the advantage of 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 min-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 (by default 60 fps)
frame 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 there is not.
UNSTABLE, IN-PROGRESS
ONLY SUPPORTED IN BROWSER
Make sure you have Node.js installed.
$ npm install taskwork
// Priorities is just an enum with default levels, you can use your own
import { Priorities, Scheduler } from 'taskwork';
// Any function, sync or async (this will be serialized and executed inside of a WebWorker)
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({
frameBudget?: number; // (Default, 1.0) Percentage of frame budget to allow for task execution
threadCount?: number; // (Default, 2 - 4 depending on CPU architecture) Amount of threads to spawn
});
async () => {
// Gets executed on first thread, returns a Promise<result>
const taskAp = scheduler.addTask(Priorities.LowPriority, getUser, [
'microsoft',
]);
// Gets executed on second thread, returns a Promise<result>
const taskBp = scheduler.addTask(Priorities.ImmediatePriority, getUser, [
'timvanscherpenzeel',
]);
// Await results
const taskA = await taskAp;
const taskB = await taskBp;
console.log(taskA, taskB); // -> 'Microsoft', 'Tim van Scherpenzeel'
};
My work is released under the MIT license.
FAQs
Efficient multi-threaded task scheduler using generic re-usable WebWorkers.
We found that taskwork demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.