Accept `URL` as `filename`
const pool = new Tinypool({
- filename: new URL('./worker.mjs', import.meta.url).href,
+ filename: new URL('./worker.mjs', import.meta.url),
})
- Convenient to use
- Align with
Workerconstructor
This should be doable, as child_process.fork() also supports it: https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options
Though we'll need to make sure it works on Windows too, as we've had URL issues there before.
I was thinking change
https://github.com/tinylibs/tinypool/blob/ec78ce94b6621a0c1234fd5aec1a1400981a31ce/src/index.ts#L304
to
this.filename = filename instanceof URL ? filename.href : filename
I don't think it related to Node.js API support
Would be very much interested in this as I have a need to run js code from a blob.
import Tinypool from "tinypool";
const sourceCode = `
export default ({a, b}) => {
return a + b;
};
`
const sourceCodeBlob = new Blob([sourceCode], { type: 'application/javascript' });
const pool = new Tinypool({
filename: URL.createObjectURL(sourceCodeBlob),
});
const result = await pool.run({ a: 1, b: 2 });
console.log(result); // Outputs: 3
await pool.destroy();
There are security features in place before this in my setup.
Currently i would need to write it to disk, which is not possible in my case.