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 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-threading

v1.0.4

Published

The brand-new solution for easy threading in node.

Downloads

12

Readme

Node-threading

The brand-new solution for easy threading in node.

Threading can sometimes be a time-consuming thing to do, and rather confusing thing aswell (Especially for beginners) That changes today, instead of messing around with isMainThread and other files we now allow you to thread a function itself! The threads are as simple, if not simplet than python threading. node-threading is an upcoming library to reïnvent how threading is done in nodejs. We are planning to see if we can sync variables across thread/parent in the near future. for now every thread is a seperate instance of node, like the included sollution in node. We currently do not have a git repo but when it is at a stable point we will create a git repo for this library. PLEASE NOTE! This libary is not ment for production products yet, you can use it in production products. But we strongly advise you not to. With that out of the way we hope you will enjoy the simplicity of node-threading

Discord: https://discord.gg/zMtJQafwhh

Examples:

let { Thread } = require("node-threading");

function foo() {
    console.log("Bar")    
}

new Thread(foo).start();
let { Thread } = require(`node-threading`);

function foo() {
    setInterval(() => {
        console.log("bar") //Send bar
    }, 90) //Enough delay to send bar 5x in 500ms
}

for (let i = 0; i < 2; i++) {
    let t = new Thread(foo);
    t.start(); //Start thread
    setTimeout(() => {
        t.terminate(); //Kill thread
    }, 500) //Allow 2 threads to send 5x Bar totaling in 10x bar
}
function foo() {
    let { Parent } = require(`./index.js`);
    let parent = new Parent();

    parent.on("test", (data) => {
        console.log(data); //logs "works"
    })
}

for (let i = 0; i < 10; i++) {
    let t = new Thread(foo);
    t.start();
    t.send("test", "works")
}

Class - Thread

Create constructor let t = new Thread(function, { cwd: dir, modules: dir}); (Options are optional)

cwd = Run directory
modules = node modules dir

Start the thread t.start();

stop the thread t.terminate();

send message to thread t.send(channel, data)

recieve message from thread t.on(channel, (data) => {})

Class - Parent

//this code must be in the thread
let { Parent } = require(`node-threading`); //Require parent from node-threading, make sure to import it from the thread as variables as of now are not shared
let parent = new Parent(); //Create new instance

get message from parent parent.on(channel, (data) => {})

send message to the parent parent.send(channel, data)

Changelog

1.0.4

* Update readme

1.0.3

+ Add parent class for IPC and getting data in the thread
+ Add IPC
+ Add thread.send and parent.send
+ Extend events to thread and parent classes

1.0.2

+ Fix require statement
+ Add thread.start() and thread.terminate()

1.0.1

+ Thread class
+ Fix Filesystem lib

1.0.0

+ Add Readme