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

@buzuli/transport

v1.0.0

Published

subprocess coordination for Node.js

Downloads

5

Readme

transport

Transport system for use by parent and child processes forked via child_process.fork().

transport.coordinator

Creates a transport for a coordinator (parent process) to direct its workers (child processes).

transport.coordinator(options)

  • options.logger: object = console | The logger which this coordinator tranport should use.

Returns { addWorker, removeWorker, setLogger, shutdown, sendConfig, sendPing, sendTask, sendCollect, sendEnd } extends EventEmitter:

  • addWorker: (proc) => id | Adds a worker process handle to the transport and returns the generated worker ID.
  • removeWorker: (id) => proc | Removes and returns the identified worker if found.
  • setLogger: (logger) => nil | Replaces the transport's logger.
  • shutdown: () => nil | Removes all listeners and handlers (permit the process to exit cleanly).
  • sendConfig: (id, config) => nil | Sends a config object to a worker (should happen after the online event).
  • sendPing: (id) => nil | Pings a worker (response event is online).
  • sendTask: (id, task) => nil | Sends a task object to a worker.
  • sendCollect: (id) => nil | Sends a collect request to a worker.
  • sendEnd: (id) => nil | Directs a worker to halt.

Events:

  • online | A worker has started and its transport is online. Is also emitted in response to a ping.
  • ready | A worker is ready to receive a task (should be after config has been received and all initialization work is completed).
  • result | A worker has sent result data (should be emitted in response to a coordinator's collect request).
  • done | A worker is halting and will not respond to any futher communication. The worker should be removed from this transport.
  • log | Should be used to transmit log data to the coordinator.

All events emit { id, data? }:

  • id: number | The ID of the worker which emitted the event.
  • data: object | The payload associated with the event (should be present in result and log events).

transport.worker

Creates a transport for a worker (child process) to receive instruction from its coordinator (parent process).

transport.worker(options)

  • options.logger: object = console | The logger which this worker transport should use.

Returns { setLogger, shutdown, sendOnline, sendReady, sendResult, sendDone, sendLog } extends EventEmitter:

  • setLogger: (logger) => nil | Replaces the transport's logger.
  • shutdown: () => nil | Removes all listeners and handlers (permit the process to exit cleanly).
  • sendOnline: (data?) => nil | Indicate that this worker's transport is active.
  • sendReady: (data?) => nil | Indicate that this worker is ready to receive a task (typically on completion of the prior task).
  • sendResult: (data) => nil | Send a result to the coordinator (should be in response to a collect event).
  • sendDone: (data?) => nil | Indicate that this worker is halting and will not respond to any further communcation from the coordinator.
  • sendLog: (data) => nil | Sends a log record to the the coordinator.

Events:

  • config | The coordinator has sent configuration.
  • task | The coordinator has assigned a new task to this worker.
  • collect | The coordinator has requested that the worker deliver any cached results.
  • end | The coordinator has requested that the worker halt.

Some events emit a data field:

  • data: object | The payload associated with the event (should be present in config and task events).

transport.run

Runs an action, with configurable handling of the outcome.

transport.run(action, options)

  • action: () => Promise | any | The function which should be run and awaited.
  • options.logger: object = console | The logger to which errors should be sent.
  • options.rethrow: boolean = true | Rethrow if an exception is caught while awaiting action().

Returns a promise which indicates the outcome of the action() function.