node:worker_threads

#Import

import worker_threads from "nstdlib/node/worker_threads";

Note

The API is available, but not everything works. No threads. new Worker() throws.

#Support

node:worker_threads. nstd: works. Browser: works; export coverage 100%.

  • nstd: Gives the same output as Node.js in side-by-side tests: worker.
  • Browser: Loads with a minimal process object. 21 of Node's 21 exports are available. 1 of 1 behavior checks match Node.js.

#Exports (21)

Every name Node.js exports from this module, and what you get when you read it, as a named import or as a property of the default import:

  • ✅ A value, both ways. An export that throws an error naming the missing feature also counts.
  • ⚠️ A value one way, undefined the other.
  • ❔ undefined both ways.
  • ❌ Not exported at all.
  • – Not measured.
ExportNode.jsBrowser
BroadcastChannel✅✅
MessageChannel✅✅
MessagePort✅✅
SHARE_ENV✅✅
Worker✅✅
getEnvironmentData✅✅
isInternalThread✅✅
isMainThread✅✅
isMarkedAsUntransferable✅✅
locks✅✅
markAsUncloneable✅✅
markAsUntransferable✅✅
moveMessagePortToContext✅✅
parentPort✅✅
postMessageToThread✅✅
receiveMessageOnPort✅✅
resourceLimits✅✅
setEnvironmentData✅✅
threadId✅✅
threadName✅✅
workerData✅✅

#Diagnostics

nstdlib running inside Node.js. This isn't an environment it's meant for, so it isn't shown above, but it tells a library problem from an environment one:

  • coverage: 21/21 of the host's export names answer inside host node. API only. No threads. new Worker() throws.
  • smoke: Imports in a clean child process.