npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@a4turp/multithreading

v1.0.0

Published

Light and easy web-tool for accessing multiple threads via web workers.

Readme

Light and easy web-tool for accessing multiple threads via web workers.

Features

  • Access to multiple threads.
  • Possibility to chain workers for each individual thread (Up to 64).
  • Multiple modes for each thread pool (keep alive | remove | First Keep Alive Rest Remove).
  • Race and regular modus for all threads.
  • Access to object parameters ("rescoping") and their modification.

Notes

This is WEB-tool.

General

import MC from '@a4turp/multithreading'
//or
const MC = require('@a4turp/multithreading').default

/**
 * @param Number
 * Limits the number of created threads. 
 * Maximum number is 'navigator.hardwareConcurrency - 1' value.
 * 
 * @description Initializes new threads/worker wrappers.
 */
MC.initialize(999)

/**
 * @param Boolean
 * Log out showcase notifications.
 * 
 * @description Runs a showcase.
 */
MC.test(true)
/**
 * @param any
 * The Parameter which is going to be passed to the functions of every worker in every thread pool.
 * @return Promise<Any>
 *     
 * @description Runs every available thread pool and returns the fastest resolved response.
 */
await MC.race()
/**
 * @param any
 * The Parameter which is going to be passed to the functions of every worker in every thread pool.
 * @return Promise<Array>
 *     
 * @description Runs every available thread pool and returns every resolved response in array.
 */
await MC.all()
/**
 * @description Restarts every thread pool.
 */
MC.restart()
// Getters
MC.limit //Thread count limit.
MC.mode //Threads controller mode: regular | race.
// Setters

/**
 * @type 'keep_alive'|'fkarr'|'remove'
 * @description sets pool mode for every thread pool.
 * 'keep_alive' After running thread, all workers remain.
 * 'fkarr' After running thread, only irst worker remains.
 * 'remove' After running thread, all workers are getting removed.
 *
 */
MC.threadsMode

Individual pool

After we initialized threads we can access our pools.


/**
 *  @description 
 *      Passed value is accessable under data subkey of the parameter.
 *      Chained function will get computed message of previous function.
 *      
 *  @note 
 *      Chained methods will accept only their own parameters.
 *      It means: only 'message' and 'exec_time' keys are accessible from previous message.
 */
function testFunc(message, exec_time) {
    const start = performance.now()
    let value = 0
    for (let i = 0; i < 1000000000; i++) value += i
    

    //postMessage is mandatory and should be used instead of return
    postMessage({
        exec_time: performance.now() - start + (exec_time ?? 0),
        message: message
    })
}

MC.threads[0].add(testFunc, /* ... */)
MC.add(0, testFunc, /* ... */)
/**
 * @param any
 * The Parameter which is going to be passed to the functions of every worker.
 * @return Promise<any>
 *
 * @description Runs every worker one after the other in the pool.
 */
MC.threads[0].run('your massage')
MC.run(0, 'your massage')
/**
 * @param Number
 * Position of the worker in array.
 * 
 * @description Removes worker from the pool.
 */
MC.threads[0].remove()
MC.remove(0)
/**
 * @description Removes last worker from the pool.
 */
MC.threads[0].pop()
MC.pop(0)
/**
 * @description Clears the pool.
 */
MC.threads[0].clear()
MC.clear(0)
/**
 * @description Terminates only the worker in the pool.
 */
MC.threads[0].softTerminate()
MC.softTerminate(0)
/**
 * @description Terminates the worker and its settings in the pool.
 */
MC.threads[0].terminate()
MC.terminate(0)
/**
 * @description Restarts workers in the pool. 
 */
MC.threads[0].restart()
MC.restart(0)
// Getters
MC.threads[0].state //State of the pool.
MC.threads[0].pool //Workers array.
MC.threads[0].name //Name of the pool.
MC.threads[0].mode //Pool mode 'keep_alive'|'fkarr'|'remove'.

MC.threads[0].isKeepingAlive //Pool keeps workers alive?
MC.threads[0].isFKARR //Pool keeps only first worker alive?
MC.threads[0].isRemoving //Pool removes all workers?
// Setters

/**
 * @type 'keep_alive'|'fkarr'|'remove'
 * @description sets pool mode.
 * 'keep_alive' After running thread, all workers remain.
 * 'fkarr' After running thread, only first worker remains.
 * 'remove' After running thread, all workers are getting removed.
 * 
 */
MC.threads[0].pool[0].mode

Individual thread

After adding workers in our thread pools, we can access each of them in pool sub key of WorkerPool class.

// .....

function testFunc(message) { /*...*/ }

/**
 * @param Function?
 * Function that will be called every time, when worker is called.
 * If no function passed, 'create' will be ignored.
 * 
 * @description Initializes worker in certain thread pool.
 */

MC.threads[0].pool[0].initialize(testFunc, testFunc)
/**
 * @param any
 * The Parameter which is going to be passed to the function.
 * @return Promise<any>
 * 
 * @description Executes the worker function.
 */
await MC.threads[0].pool[0].run('your message')
/**
 * @description Restarts the worker.
 */
MC.threads[0].pool[0].restart()
/**
 * @description Terminates only the worker.
 */
MC.threads[0].pool[0].softTerminate()
/**
 * @description Terminates the worker and its settings.
 */
MC.threads[0].pool[0].terminate()
// Getters
MC.threads[0].pool[0].state //state of the worker.
MC.threads[0].pool[0].method //eval(method).
MC.threads[0].pool[0].bytes //uint8 array buffer of method.
MC.threads[0].pool[0].url //worker url.

MC.threads[0].pool[0].isReady //worker is ready?
MC.threads[0].pool[0].isRunning //worker is running?
MC.threads[0].pool[0].isSleeping //worker is sleeping?

Changes

| Version | Type | Date | Description | |---------|:-------:|:--------:|:-----------------------------------------------------------------| | 0.2.0 | change | 10.02.23 | Callback is not editable. | | 0.4.0 | change | 28.03.23 | Threads limit changed to navigator.hardwareConcurrency - 1. | | 0.4.0 | change | 28.03.23 | Threads are located in 'threads' array parameter. | | 0.4.0 | change | 28.03.23 | Threads are pools of worker wrappers. | | 0.4.0 | feature | 28.03.23 | Pools are able to chain functions. 🤩 | | 0.4.0 | change | 28.03.23 | Workers are now getting initialized my initialize method. | | 0.4.1 | fix⚠️ | 29.03.23 | Fixed method parsing for static and regular class methods. | | 0.5.0 | fix⚠️ | 30.03.23 | Finally fixed import for npm. | | 0.5.0 | feature | 30.03.23 | Finally added require support. | | 0.6.0 | feature | 07.04.23 | Support of scope modification. ⭐️ | | 0.6.0 | change | 07.04.23 | Pool access shortcuts. | | 0.6.2 | fix⚠️ | 12.04.23 | Fixed module requiring. | | 0.6.3 | fix⚠️ | 12.04.23 | Removed assets. | | 0.6.* | dev🧪 | 17.04.23 | Development changes. | | 1.0.0 | fix⚠️ | 17.04.23 | Fixed short key assigning issue. |