Skip to content

ajkachnic/cursedthread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

threading api for node

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published