workerfy

0.0.1 • Public • Published

workerfy

Takes a (expensive) function and offloads it to a worker thread. Heavily inspired by promisfy and workerize.

Warning

DO NOT USE (YET)

Does not work under some circumstances, because workerfy relies on being able to stringify the passed function. Bound functions always return "function () { [native code] }" when being stringified. Inline functions that use closured values won't work.

const a = 1;
workerfy(() => a + 1); // will not work

Methods that access this.

Example

index.js

async function parseScript(script) {
  const workerfy = require('workerfy');
  const parse =  workerfy(require('some-js-parsing-library'));
  const result = await parse(script);
}

node --experimental-worker index.js

Readme

Keywords

none

Package Sidebar

Install

npm i workerfy

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

4.01 kB

Total Files

6

Last publish

Collaborators

  • robin-drexler