All Projects → developit → Task Worklet

developit / Task Worklet

Licence: apache-2.0
Task Worklet: explainer, polyfill and demos.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Task Worklet

Thread
type safe multi-threading made easier
Stars: ✭ 34 (-86.77%)
Mutual labels:  worker, threading
Comlink Loader
Webpack loader to offload modules to Worker threads seamlessly using Comlink.
Stars: ✭ 535 (+108.17%)
Mutual labels:  threading, worker
wasm-mt
A multithreading library for Rust and WebAssembly
Stars: ✭ 121 (-52.92%)
Mutual labels:  threading
Track-Stargazers
Have fun tracking your project's stargazers
Stars: ✭ 38 (-85.21%)
Mutual labels:  threading
tgrid
TypeScript Grid Computing Framework supporting RFC (Remote Function Call)
Stars: ✭ 83 (-67.7%)
Mutual labels:  worker
polog
Логирование должно быть красивым
Stars: ✭ 26 (-89.88%)
Mutual labels:  threading
disrustor
A port of the LMAX Disruptor to Rust
Stars: ✭ 29 (-88.72%)
Mutual labels:  threading
humanbenchmark
Memory tests solver with using OpenCV
Stars: ✭ 20 (-92.22%)
Mutual labels:  threading
awesome-dotnet-async
A curated list of awesome articles and resources to learning and practicing about async, threading, and channels in .Net platform. 😉
Stars: ✭ 84 (-67.32%)
Mutual labels:  threading
amqp-delegate
A simple, but performant, remote worker system that uses AMQP to coordinate jobs.
Stars: ✭ 22 (-91.44%)
Mutual labels:  worker
celery.node
Celery task queue client/worker for nodejs
Stars: ✭ 164 (-36.19%)
Mutual labels:  worker
wolfpacs
WolfPACS is an DICOM load balancer written in Erlang.
Stars: ✭ 1 (-99.61%)
Mutual labels:  worker
psched
Priority-based Task Scheduling for Modern C++
Stars: ✭ 59 (-77.04%)
Mutual labels:  threading
argobots
Official Argobots Repository
Stars: ✭ 71 (-72.37%)
Mutual labels:  threading
Worker
The Hoa\Worker library.
Stars: ✭ 25 (-90.27%)
Mutual labels:  worker
dbmq
Docker-based Message Queuing
Stars: ✭ 39 (-84.82%)
Mutual labels:  worker
soabase-stages
A tiny library that makes staged/pipelined CompletableFutures much easier to create and manage
Stars: ✭ 23 (-91.05%)
Mutual labels:  threading
workit
Extensible worker for Node.js that works with both Zeebe and Camunda BPM platforms powered by TypeScript
Stars: ✭ 51 (-80.16%)
Mutual labels:  worker
dannyAVgleDownloader
知名網站avgle下載器
Stars: ✭ 27 (-89.49%)
Mutual labels:  threading
mi-prometheus
Enabling reproducible Machine Learning research
Stars: ✭ 41 (-84.05%)
Mutual labels:  worker

Task Worklet

A polyfill for Task Worklet - a proposed API for defining and invoking coordinated, threadpooled background tasks with minimal transfer overhead.

Motivation

A lot of what we do in modern web applications touches the DOM in some way. Improving the performance of DOM-bound code is difficult because issues generally stem from layout and paint cost rather than actual script execution overhead. Task Worklet attempts to define a highly ergonomic way to offload all of the work an application needs to do that doesn't rely on the DOM, while making it incredibly easy to move data between the UI thread and background threads.

In addition to ergonomics, the design of Task Worklet allows for an implicit data flow graph to be formed based on how tasks are linked together to form dependencies on one another. When combined with pooling and a centralized registry for task processors, this enables an algorithm to distribute work across multiple threads, automatically maximizing concurrency and minimizing transfer overhead.

Demo: Realtime JS compilation, bundling & compression

Usage

First, install the script via npm install task-worklet or grab it from unpkg.

By default, the task-worklet ships as an npm module that exports the TaskQueue interface.

If you'd prefer to "install" it as window.TaskQueue, go for task-worklet/polyfill:

<script src="https://unpkg.com/task-worklet/polyfill"></script>

Once you have it imported/installed, we can start interacting with the TaskQueue:

// create a queue a max threadpool size of 1:
const queue = new TaskQueue();

// add a Task Worklet:
queue.addModule('/fetch-worklet.js').then(() => { /* loaded */ })

const task = queue.postTask('fetch', 'https://example.com/data.json');

console.log(task.state);  // pending

await sleep(1);

console.log(task.state);  // scheduled

// now we'll ask for the result back. This bumps up the priority
// of the task and sends its result to the main thread once complete:
const result = await task.result;
console.log(result)  // { ..some data.. }

Here's the key: task.result is a lazy getter. If you don't ask for a Task's result by accessing .result, it will be kept in whatever background thread ran the task until it's needed.

Why keep task results in the thread that ran the task? That's the best part: we can pass Task instances to postTask(), and instead of "pulling" the result of a task back to the main thread and sending it on to the thread that's running that second task, the second task will be routed to the thread that already has the first's result waiting:

const data = q.postTask('fetch', 'https://example.com/data.json');

const subset = q.postTask('filter', data, ['items', 'count']);

// we only end up with the subsetted data on the main thread:
console.log(await subset.result);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].