1.0.1 • Published 2 years ago

cursedthread v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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)
1.0.1

2 years ago

1.0.0

2 years ago