Web workers on steroids really.
v-thread
is a library that gives you bunch of amazing features and neat goodies when working with web workers.
Goodies include but not limited to:
- Abstracting away
postMessage
andonmessage
so you can focus on your code, - Being able to kill workers gracefully, giving them time to do clean up and stuff,
- Ability to pass additional data when workers are created,
- Enhancing errors, i.e if an error is thrown in
Worker
, final stack trace will also include calls in main thread that led to that error, so you know what's really going on
And the best of all, [brace yourself], being able to call methods defined in worker directly, just like you're used to.
Example
Let's say you're making WebGL
app or similar. You might wanna do heavy computation inside a worker to avoid blocking the main (UI) thread.
v-thread
can really ease the process.
Install
$ npm i v-thread
Light it up
// main.js async { // start thread const thread = VThreadstart'worker.js'; // get proxy const worker = thread; // have fun const bitmap = await worker; }; // ...
// worker.js ; // ... async { const frame = await this; const camera = this; const scene = this; return scenergbBitmap; } VThreadable; // ...
That's it!
Power of multi-threading, without the pain.
Browser support | |
---|---|
Chrome | 49 |
Firefox | 18 |
Edge | ✅ |
Opera | 36 |
Safari | 10 |
IE | ⛔ |
Edge on desktops requires version 12 or above
Head over to documentation for more info on whats available.
Related
co-web-worker - Cross-origin web workers. Works with v-thread
text-store - Super performant text container for working with massive text files