piscina icon indicating copy to clipboard operation
piscina copied to clipboard

How to create Piscina instance by passing function instead of filename

Open alex-uw opened this issue 3 years ago • 3 comments

I'd like to have flexibility to pass arbitrary worker function, not a worker file name Is this possible? thanks

alex-uw avatar Jul 22 '21 17:07 alex-uw

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.

jasnell avatar Jul 22 '21 19:07 jasnell

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

uzair004 avatar Aug 01 '21 17:08 uzair004

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 👍

yvele avatar Jun 04 '22 22:06 yvele