
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@dandre3000/thread
Advanced tools
Thread is a class that features a consistent API for using Workers on a web browser, node, bun or deno. All Threads are interconnected and can import modules to and call functions from each other.
npm install @dandre3000/thread
import { Thread } from '@dandre3000/thread'
// When a Thread is created
Thread.eventTarget.addEventListener('online', event => console.log('online event', event.thread.id, Thread.id))
// When a Thread has closed
Thread.eventTarget.addEventListener('exit', event => console.log('exit event', event.threadId, Thread.id))
// This function is exposed to other Threads
Thread.expose('test', (...args) => {
return `Thread ${Thread.id} says: YO`
})
if (Thread.isMainThread) {
console.log(Thread.id) // 0
console.log(Thread.workerData) // null
console.log(Thread.mainThread) // null
Thread.create(999).then(async thread => {
await thread.import(new URL(import.meta.url))
console.log(await thread.invoke('test')) // Thread 1 says: YO
})
} else {
console.log(Thread.id) // 1
console.log(Thread.workerData) // 999
console.log(Thread.mainThread) // Thread instance for main thread
}
True if the current thread is the main thread.
Identifier for the current thread.
Data sent to a thread upon creation.
Array of objects that will be transfered and emptied whenever another thread uses Thread.prototype.invoke to call a function on this thread made available using Thread.expose.
// transfer a MessagePort from a worker to the main thread
import { Thread } from '@dandre3000/thread'
if (Thread.isMainThread) {
const thread = await Thread.create()
await thread.import(new URL(import.meta.url))
;(await thread.invoke('getPort')).postMessage('Transfer successful')
} else {
Thread.expose('getPort', () => {
const { port1, port2 } = new MessageChannel
port1.addEventListener('message', ({ data }) => console.log(data))
port1.start()
Thread.transfer.push(port2)
return port2
})
}
The target for events broadcasted from other threads.
import { Thread } from '@dandre3000/thread'
Thread.eventTarget.addEventListener('online', event => console.log(event))
Thread.eventTarget.addEventListener('exit', event => console.log(event))
The Thread instance connected to the main thread if the current thread is a worker otherwise null.
Return a Promise that resolves to a new Thread. This method is the only way to create a new Thread.
Return the Thread corresponding to the given threadId or return null if no online Thread exists where Thread.id === threadId.
Return an array of all online Threads.
Make a function available to other threads when using Thread.prototype.invoke.
Remove a function from those available to other threads when using Thread.prototype.invoke.
Alias for globalThis.close or process.exit.
Identifier for this Thread instance.
Returns true until the thread is closed.
Dynamically import an ES module to the thread and return a Promise that resolves when the module is loaded.
Call a function on the thread added using Thread.expose and return a Promise that resolves to the value returned by that function.
Close this Thread instance.
FAQs
A class for managing web and node.js Workers.
The npm package @dandre3000/thread receives a total of 9 weekly downloads. As such, @dandre3000/thread popularity was classified as not popular.
We found that @dandre3000/thread demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.