Skip to content

robin-drexler/workerfy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

workerfy

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

Warning

DO NOT USE (YET)

This is only a proof of concept as of now. 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 as well.

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

Methods that access this also can't be used.

Currently it also creates a new worker instance for each invocation, because I was not able to prevent the node process from hanging otherwise. I.e. I could not figure when/how to terminate the workers.

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published