piscina
piscina copied to clipboard
How to create Piscina instance by passing function instead of filename
I'd like to have flexibility to pass arbitrary worker function, not a worker file name Is this possible? thanks
No, that's not currently possible. We're limited here by how Node.js worker threads are loaded and those do not currently support initialization by passing a function.
No, that's not currently possible. We're limited here by how Node.js worker threads are loaded and those do not currently support initialization by passing a function.
Yes that's true, But this feature is available in workerpool library
Yes that's true, But this feature is available in workerpool library
workerpool implements a basic function serialization/deserialization using new Function
(kind of eval).
This looks handy at first glance but you will rapidly hit limitations:
- https://github.com/josdejong/workerpool/issues/178#issuecomment-703083782
- https://github.com/josdejong/workerpool/issues/189
- etc..
And the real solution is to use a bundler (Webpack, rollup..)
Note that TC39 is working on a proposal regarding sharing functions and code to workers: https://github.com/tc39/proposal-js-module-blocks 👍