Registry / http-networking / threadedclass

threadedclass

JSON →
library1.4.0jsnpmunverified

Fork a class instance into a separate thread (Node.js Worker Threads or Web Workers) while preserving TypeScript typings. v1.4.0 is stable with a mature API. Key differentiators: one-liner thread instantiation, automatic method promisification, optional auto-restart on crash, and thread pooling via ThreadedClassManager. Actively maintained with frequent releases, supports Node ≥8 and modern browsers.

npm install threadedclass
INSTALL
IMPORT
SIG · THREADEDCLASS
T
threadedclass
http-networkingjavascriptv1.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

threadedClass
import { threadedClass } from 'threadedclass'
import threadedClass from 'threadedclass'
Default export does not exist; always use named import.
ThreadedClassManager
import { ThreadedClassManager } from 'threadedclass'
const ThreadedClassManager = require('threadedclass').ThreadedClassManager
Named import in ESM. In CJS, use const { ThreadedClassManager } = require('threadedclass').
ThreadedClassConfig
import type { ThreadedClassConfig } from 'threadedclass'
TypeScript consumers can import the config type for type safety. Not available at runtime.

Creates a forked instance of Professor class running in a separate thread. Constructor arguments are passed as array; all methods become async.

import { threadedClass } from 'threadedclass'; // Assume ./professor.ts exports class Professor with methods like talkAboutAncientGreece() const mrSmith = await threadedClass<Professor>( './professor.js', // path to compiled JS file 'Professor', ['maths', 'greek'], // constructor args { autoRestart: true } // optional config ); // All methods return promises const story = await mrSmith.talkAboutAncientGreece(); console.log(story);
Debug
Known issues
gotchaThe module path must point to the compiled JavaScript file, not the TypeScript source. Using .ts will cause runtime errors.
fix
Use the compiled output path (e.g., './professor.js').
affects: >=1.0.0
deprecatedThe `threadUsage` option is deprecated. Use `ThreadedClassManager.setThreadUsage()` for thread pool control.
fix
Use `ThreadedClassManager.setThreadUsage(0.1)` instead of passing `threadUsage` in config.
affects: >=1.2.0
breakingIn v1.0.0, the `threadedClass` function returned the instance directly (sync). Since v1.1.0 it returns a Promise, breaking old code that did not use await.
fix
Add `await` before calling `threadedClass()`.
affects: >=1.1.0
gotchaProperties of the class are not accessible on the forked instance: only methods are promisified. Accessing a property returns `undefined`.
fix
Convert properties to getter methods (e.g., `getName()` instead of `name`).
affects: >=1.0.0
gotchaIn browser environments, you must provide `pathToWorker` in the config, otherwise the worker script won't be found.
fix
Set config option `pathToWorker: 'lib/threadedclass-worker.js'`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: threadedClass is not a function
Default import used instead of named import.
fix
Use `import { threadedClass } from 'threadedclass'` or `const { threadedClass } = require('threadedclass')`.
Cannot find module './professor.js'
The compiled JS file path is incorrect or the module is not yet compiled.
fix
Ensure the path points to the .js file after compilation (e.g., ./professor.js). Compile TypeScript first.
Error: Class constructor must be invoked with 'new'
Passing the class object directly instead of the export name string in Node.js.
fix
Use the second argument as a string: `threadedClass('./professor.js', 'Professor', ...)`. In browser, you must pass the class reference.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
threadedclass — npm install threadedclass · libregistry