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

ipc-emitter

v0.2.1

Published

EventEmitter for IPC connected node apps.

Downloads

6

Readme

Build Status JavaScript Style Guide npm version

ipc-emitter

Installation

npm install --save ipc-emitter

Master

const {master} = require('ipc-emitter')

Master is an EventEmitter, with a few differences.

When it emits an event (using the .emit() function) apart from triggering its own listeners, it also notifies other acknowledged processes (i.e. Workers) through the IPC Channel (using process.send() method).

In addition to this, it also listens for events emitted by acknowledged processes (by listening for their message event) so that it triggers its own listeners and also notifies other acknowledged processes to trigger their own (note that the process which triggered the event is not notified).

When getting a Master IPC-Emitter it will always return a new object.

API

.ack( process [, process[...] ] )

Acknowledges a process (Worker). Doing so the Master:

  1. Will be listening for any events the newly acknowleged process might emit so that it can trigger its own listeners and notify other acknowledged processes.
  2. Will notify the newly acknowledged process of any events emitted either the master or other acknowledged processes.

.forget( process [, process[...] ] )

Removes a process (Worker) from the list of acknowledged processes. Doing so the Master:

  1. Will stop listening for any events the newly forgotten process might emit.
  2. Will stop notifing the newly forgotten process of any events emitted either by the master or other acknowledged processes.

.echo()

Configures the Master to:

  1. Echo payloads retrieved by its master to its workers.
  2. Echo payloads retrieved by its workers to its master.

.stopEcho()

Configures the Master to stop echoing events.

.echoUp()

Configures the Master to echo events retrieved by its Workers, to its own Master.

When a Master is configured to echo events to its own Workers, if itself is not a Worker a warning is issued.

.stopEchoUp()

Configures the Master to stop echoing events retrieved by its Workers, to its own Master.

.echoDown()

Configures the Master to echo events retrieved by its own Master, to its Workers.

When a Master is configured to echo events from its own Master, if itself is not a Worker a warning is issued. When a Master is configured to echo events from its own Master, when it recieves an event from the Master, its listeners won't be triggered (this is the work of the Worker).

.stopEchoDown()

Configures the Master to stop echoing events retrieved by its own Master, to its Workers.

Worker

const {worker} = require('ipc-emitter')

Worker is an EventEmitter, with a few differences.

When it emits an event (using the .emit() function) apart from triggering its own listeners, it also notifies its master process through the IPC Channel (using process.send() method). Doing this if the Master Process is using the Master IPC-Emitter, the event will be echoed to all of the acknowledged workers.

When getting a Worker IPC-Emitter will always return the same object.

Example

boot.js

'use strict'

const {fork} = require('child_process')
const {master} = require('ipc-emitter')

master.on('new-user', (userId) => {
  console.info(`boot: new user: ${userId}`)
})

master.ack(fork('./auth'), fork('./log'))

log.js

'use strict'

const {worker} = require('ipc-emitter')

console.info('Logger initiated')

worker.on('new-user', (userId) => {
  console.info(`log: new user: ${userId}`)
})

auth.js

'use strict'

const {worker} = require('ipc-emitter')

console.info('Auth initiated')

setTimeout(() => {
  worker.emit('new-user', 1)
}, 2000)

Output

Logger initiated
Auth initiated
boot: new user: 1
log: new user: 1