Socket
Book a DemoInstallSign in
Socket

facehugger

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

facehugger

back-packed child-process with callback stack

1.6.0
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

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);

Keywords

backpack

FAQs

Package last updated on 21 Jul 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.