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

apex-threading

v0.0.3

Published

Apex Framework: Threading Component

Readme

Apex: Threading Component

(!) work in progress.

Providers native multi-threading support using web workers.
Requires electron where nodeIntergration and nodeIntegrationInWorker is enabled.

Installation

Using npm:

$ npm i apex-threading --save

Using yarn:

$ yarn add apex-threading

Usage

See this example for a test using prime number generation.

const my_thread = new Threading.Thread(() => {
    // This code runs in a thread and in its own scope. Parent variables/scopes are
    // unavailable here.
    
    on('upper', (str) => {
        emit('upper-result', str.toString().toUpperCase());
    });
});

my_thread.on('upper-result', (str) => {
    console.log('Response from thread: ', str);
});

// Sending a message on a thread that has not been started yet, will start it automatically.
my_thread.send('upper', 'hello world');
// > "Response from thread: HELLO WORLD

// Kill the thread.
my_thread.terminate();

// Start it again if you want.
my_thread.start();

Threads

A thread is defined by a function body. The function may be defined anonymously (inline) as seen in the example above, or an external file where a function is exposed using module.exports and required in the function argument.

The function runs in a separate scope, meaning that this wil not work:

const a = 1234;
const t = new Thread(() => {
    console.log(a); // undefined
});

A thread has two global functions that it can use to communicate back and forth with the main process:

  • on(type, callback)
  • emit(type, data)

The same functionality is also available on the Thread instance, but instead of using emit, you'll have to use send with the same syntax.

For example:

const my_thread = new Thread(() => {
    on('to-upper', (str) => {
        emit('to-upper-result', str.toString().toUpperCase());
    });
});

my_thread.on('to-upper-result', (str) => {
    console.log('result: ', str);
});

my_thread.send('to-upper', 'hello world');

Global listeners.

If you spawn a lot of threads with the same features (like logging for example), you might want to add a listener to all available threads simultaneously. You can do this by using the ThreadPool. This will only work on threads spawned by the ThreadPool.

const Threading = require('apex-threading');

Threading.ThreadPool.spawn('thread_1', require('./thread-script.js'));
Threading.ThreadPool.spawn('thread_2', require('./thread-script.js'));
Threading.ThreadPool.spawn('thread_3', require('./thread-script.js'));

Threading.ThreadPool.on('log', (type, message) => {
    console.log('[' + type + ']: ', message);
});

In the example above, if any thread executes emit('log', 'some message'), it will be picked up by that one listener.