Socket
Book a DemoInstallSign in
Socket

cluster-callresp

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cluster-callresp

A call-and-response message passing system for node's cluster builtin

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

cluster-callresp

An easy way to set up "call and response" type messages using node's builtin "cluster" module.

// master.js
var callresp = require("cluster-callresp")

callresp(function (call, cb) {
  // depending on the content of call,
  // do some magic, and then later:

  cb(er, response)
})

// calling callresp just adds another listener
callresp(function (call, cb) {
  if (call.request == "myThing") {
    goGetMyThing(call, cb)
  }
  // otherwise just do nothing, must have been
  // for someone else.
})

Then in the worker:

// worker.js

var callresp = require("cluster-callresp")

// make a call, and then eventually get a response.
// Callback is optional, if you just want to send a message,
// but don't care about the response.
// Set a 'timeout' property to fail if there's no response in
// a specific number of ms.  By default, waits forever.
callresp({ request: "myThing", details: "go get it!" }, function (er, resp) {
  if (er) return handleError(er)
  var results = resp.data
})

FAQs

Package last updated on 24 Apr 2012

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