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

facehugger

v1.6.0

Published

back-packed child-process with callback stack

Downloads

19

Readme

facehugger

back-packed child-process with callback stack and more batteries included

Build Status

Info

  • allows you to spawn a child process to offload work
  • implements a simple interface to ensure the worker is always running (e.g. restarts automatically)
  • interface allows event (send/receive) as well as direct (sync promise e.g. runTask().then(result => {}) actions
  • also ships with runQueueTask().then(result => {}) api to enqueue worker requests (prevent overload/enable backpressure)
  • child and parent processes stay debuggable

Install via

npm i facehugger

Parent Setup

const { FaceHugger } = require("facehugger");

const moduleFile = "./../../test/TestProcess.js";
const log = new Logger({level: "DEBUG"}); //e.g. log4bro
const config = {
    autoRestart: true,
    forkDelay: 10
};

const faceHugger = new FaceHugger(moduleFile, log, config);
faceHugger.start({}); //you can pass init data

//some available events
faceHugger.once("ready", () => {});
faceHugger.on("restart", () => {});
faceHugger.on("close", () => {});
faceHugger.on("message", message => {});
faceHugger.on("metrics", metrics => {});

faceHugger.pullMetrics({}, 1000) //arg, timeout in ms
    .then(metrics => {});

faceHugger.runTask("sometask", {}, 200) //taskname, arg, timeout in ms
    .then(result => {})
    .catch(error => {});

faceHugger.restart(); //kills and spawns child process
faceHugger.stop(); //kills child process and halts

Child Setup

const { ForkProcess } = require("facehugger");

const fork = new ForkProcess();

const processCallback = data => {
     fork.log("ready");
     //run something to keep the process alive
     setInterval(() => {}, 1000); 
};

const metricsCallback = cb => {
    cb(null, {
        //return whatever you like
    });
};

//register callbacks (that can be called from the parent process)
fork.register("sometask", (data, callback) => {
    process.nextTick(() => {
        fork.log(data);
        callback(null, "yeah");
    });
});

fork.connect(processCallback, metricsCallback);