worker-fns

Collection of Modern Worker Utility Functions

Usage no npm install needed!

<script type="module">
  import workerFns from 'https://cdn.skypack.dev/worker-fns';
</script>

README

worker-fns

Collection of Modern Worker Utility Functions

features

  • modern ES6 syntax
  • cross-platform (works on the Web and in NodeJS)
  • automatically create transfer list

functions

Documentation for the following can be found here

install

npm install worker-fns

simple example

import { postMessageWithAutoTransfer } from 'worker-fns';

const worker = new Worker("./worker.js");
const response = await fetch("./example.dat");
const data = await response.arrayBuffer();

// automatically transfer ownership of array buffer
// to the worker thread avoiding unecessarily copying the data
postMessageWithAutoTransfer(worker, data);