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

partner

v0.6.1

Published

Child process management. Support to create, manage, interact between child process.

Downloads

1,883

Readme

partner

Wrapping require("child_process") module. Supporting to manage child process status such as start, stop. Handle message, exit status, request/response between parent and child.

Installation

npm install partner

Usage

var partner = require("partner");

partner.on("start", function(data, master, done){ })

Handling start event.

start start event.

function(data, master, done) callback function.

  • data Start argument.
  • master false it is child process otherwise callback is invoked from partner.start([data], [function(error){ }])
  • done(error) callback notify to master.

partner.on("stop", function(data, master, done)){ })

Handling stop event.

stop stop event.

function(data, master, done) callback function.

  • data Stop argument.
  • master false it is child process otherwise callback is invoked from partner.stop([data], [function(error){ }])
  • done(error) callback notify to master.

partner.on("message", function(message, data, master){ })

Handling message.

message message event.

function(message, data, master) callback function.

  • message Message name.
  • data Data payload
  • master false it is child process otherwise callback is invoked from partner.send(message, data, [sendHandle])

partner.handle(function(message, data, response){ })

Handling request from parent

function(message, data, response) callback function.

  • message Message name.
  • data Data payload
  • response Callback function(error, data). Invoke to send response to parent.

partner.request(message, data, function(error, data, message){ })

Request parent handle.

  • message Message name.
  • data Data payload
  • function(error, data, message) callback function.

partner.with(modulePath|alias, [strategy])

Asking parent dispatches request/message from other children by module path or alias.

  • module|alias Module file path or alias to handle request.
  • strategy Strategy for select partner to handle. There are: "first", "last", "next", "random", index-number

var friend = partner.with("modulePath", [strategy])

  • friend.request(message, data, function(error, data, message)){ }) Request handle
  • friend.send(message, data, [sendHandle]) Send message.
  • friend.register(function(message, data) { ... }) Register handle message.
  • friend.unRegister(function(message, data) { ... }) Unregister handle message.

partner.select(modulePath|alias, [strategy]);

Select a child by file path or alias and request handle with strategy.

  • module|alias Module file path or alias to handle request.
  • strategy Strategy for select partner to handle. There are: "first", "last", "next", "random", index-number

var child = partner.select("modulePath", [strategy])

  • child.request(message, data, function(error, data, message)){ }) Request handle
  • child.send(message, data, [sendHandle]) Send message.

partner.send(message, data, [sendHandle])

Sending message. If itself is child process then send back to parent, otherwise raise "message" event for itself.

  • message Message in string format.
  • data Data payload.

partner.broadcast(message, data, [sendHandle])

Sending message for all children process.

  • message Message in string format.
  • data Data payload.

partner.stop([data], [function(error){}])

Sending current process. If itself is child process then do nothing, otherwise raise "stop" event for itself.

  • data Optional data payload.
  • function(error) callback function.

partner.start([data], [function(error){}])

Start current process. If itself is child process then do nothing, otherwise raise "start" event for itself.

  • data Optional data payload.
  • function(error) callback function.

partner.list(): Array

List all children process.

partner.create(modulePath, [alias]): object

Create child process with JavaScript file path, alias. Return new partner object with methods:

var child = partner.create("file://./child.js");

  • child.setOptions(options) set options for child process like: child_process.fork(modulePath, [args], [options]).

  • child.getOptions() get options.

  • child.setArguments(args) set arguments for child process like: child_process.fork(modulePath, [args], [options]).

  • child.getArguments() get arguments.

  • child.getFile() get absolute file path.

  • child.get() get ChildProcess object.

  • child.start([data], [callback]) start child process with argument data. Callback if partner invoke done([error], [data])

  • child.stop([data], [callback]) stop child process with argument data. Callback if partner invoke done([error], [data])

  • child.send(message, data, [sendHandle]) send message to child process with data and sendHandler

  • child.request(message, data, function(error, data, message){ }) request child process message and waiting for response in callback.

  • child.broadcast(message, data, [sendHandle]) send message to all children process except itself with data and sendHandler.

  • child.exit() force child process must stop.

  • child.on("message", function(message, data){} ) handle message event is sent back from child.

  • child.on("exit", function(errors, data){} ) handle exit event if child is kill or die. Data is start data.

  • child.handle(function(message, data, response){ }) handle request from child.

Examples

TODO

  • Support socket.io to connect other process cross network.

License

MIT