cursedthread
v1.0.1
Published
create worker threads in javascript with a Promise-like API!
Downloads
3
Readme
cursedthread
create worker threads in javascript with a Promise-like API!
import { Thread } from "cursedthread";
// Spawned in a Worker Thread
const result = await Thread(name => {
return `hello ${name}!`
}, "bob")
api
function Thread<Args extends Array, ReturnValue>(
func: (...Args) => ReturnValue,
...args: Args
): Promise<ReturnValue>;
how?
- magic
- call
func.toString()
and then parse with a javascript parser - do some fun AST manipulations
- create a new worker with
{ eval: true }
- wrap the worker in a promise
caviots
- you can't reference values from outside the function context (all necessary params must be passed in as arguments)