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

publet

v0.0.1

Published

`npm install publet`

Downloads

12

Readme

#publet

npm install publet

Redis publish/subscribe with EventEmitter interface and efficient Buffer support.

##Testing

To test, make sure you have a running redis-server.

  1. cd into node_modules/publet
  2. npm install ./
  3. make test

To benchmark Publet against zeromq, make bench. The benchmark compares sending 50000 strings and buffers from forked child processes using the zeromq.node module in push/pull mode and Publet in emitter/receiver mode.

##Example

To operate a fully-fledged emitter/receiver, two Redis clients are required. Emitted events are queued until both the emitter and receiver client are connected and ready.

var publet = require('publet');
var emitter = publet();

emitter.on('data', function(data) {
  console.log('Data', data);
});

emitter.emit('data', 'Greetings');

##publet.{emitter, receiver}

However, you might not always need an emitter/receiver. Sometimes either is fine. In this case we don't bother synchronizing, so the startup time should be marginally faster.

var cluster = require('cluster');
var cpus = require('os').cpus().length;
var publet = require('publet');

if (cluster.isMaster) {
  var receiver = publet.receiver();
  receiver.on('message', function(msg) {
    console.log(msg); // 'greetings'
  });
  while (cpus--) clsuter.fork();
} else {
  var emitter = publet.emitter();
  emitter.emit('message', 'greetings');
};

##Buffers

Publet supports Buffers. And don't worry, it does not JSON.stringify an entire Node Buffer object. However, the buffer-to-arraylike-object conversion is marginally slower than plain other JSON.stringifiables.

var publet = require('publet');
var emitter = publet();

emitter.on('message', function(msg) {
  console.log(Buffer.isBuffer(msg), msg.toString()); // true 'test'
});

emitter.emit('message', new Buffer('test'));

##EventEmitter API

Publet's constructor tries not to clobber your namespace too good. Publet also tries to preserve the EventEmitter API. This means you could extend a Publet EventEmitter much in the same way that you could extend a regular Node EventEmitter.

var util = require('util');
var publet = require('publet');

function Sender() { 
  publet.EventEmitter.apply(this);
};

util.inherits(Sender, publet.EventEmitter);

Sender.prototype.send = function() {
  this.emit.apply(this, arguments);
};

Sender.prototype.listen = function(event, callback) {
  this.addListener(event, callback);
};

var sender = new Sender;

sender.on('ready', function() {
  sender.listen('message', function(msg) {
    console.log(msg); // 'test'
  });
  sender.send('message', 'test');
});