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

peer-emitter

v0.0.2

Published

acknowledgeable events

Downloads

8

Readme

peer-emitter

remote events with semantic acks

usage

fire-and-forget events

Works just like a remote event emitter.

send


var emitter = PeerEmitter(duplexStream);
emitter.emit('evt1', arg1, arg2);

receive


var emitter = PeerEmitter(duplexStream);

emitter.on('evt1', function(arg1, arg2) {
  console.log(arg1, arg2);
});

acknowlegded events

Just add a callback

send

Add a callback when emitting the event to make it acknowlegeable.


var emitter = PeerEmitter(duplexStream, { timeout: 1000 });

// using a callback makes the event require to be acknowlegded
emitter.emit('evt1', arg1, arg2, function(timeout) {
  if (timeout)
    console.log('evt1 timedout');
  else
    console.log('evt1 has been acknowlegded by the other end');
});

// you can specify custom timeouts per emit like so
function onAck(timeout) {
  if (timeout)
    console.log('evt1 timedout');
  else
    console.log('evt1 has been acknowlegded by the other end');
}
onAck.timeout = 3000;
emitter.emit('evt2', arg1, arg2, arg3, onAck);

receive

Add one more argument to the event handler to control when the ack is sent.
If you do not use an extra argument, and the event is acknowlegeable, ack is sent after the event handler is called.


var emitter = PeerEmitter(duplexStream);

emitter.on('evt1', function(arg1, arg2, ack) {
  console.log(arg1, arg2);

  // ack must always be called
  ack();
});

acknowlegded streams

make sure everything gets there

readable


var emitter = PeerEmitter(duplexStream);

// Creating a stream need a name for the objects that are sent or
// received so you can have multiple streams over the same emitter
// as long as they have different names.
// Nice names are names of the data types that are transacted.
// e.g. you can have a stream of apples, and a stream of oranges
var readStream = emitter.ReadStream('alpha');

// To ack each item, you will need to write it to an ack stream
var ackStream = readStream.AckStream();

readStream.on('data', function(alphas) {
  ackStream.write(alphas);
});

writable


var emitter = PeerEmitter(duplexStream);

// creating a stream need a name for the objects that are sent or
// received so you can have multiple streams over the same emitter
// as long as they have different names.
var writeStream = emitter.WriteStream('alpha');
s.pipe(writeStream);

// You also may want to extract an acknowledgement stream for the alpha channel
var ackStream = writeStream.AckStream();
ackStream.on('data', handleAck);

function handleAck(o) {
  console.log('%j got delivered', o);
}

// if you want acks, you probably want to know if they fail aswell
var timeoutStream = writeStream.TimeoutStream( { timeout: 6000 } );
timeoutStream.on('data', handleTimeout);

function handleTimeout(o) {
  console.log('%j timed out');
}