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

promissory-arbiter

v1.0.1

Published

An asynchronous, hierarchical, topic-based, promissory implementation of the pub-sub pattern

Downloads

60

Readme

Promissory Arbiter Build Status Test Coverage Code Climate NPM version devDependency Status

Sauce Test Status

An asynchronous, hierarchical, topic-based, promissory implementation of the pub-sub pattern

Getting Started

Getting arbiter up and running is simple. It can be used as a node_module on the client (using WebPack et al.) or on the server. It can even be downloaded and set into a third_party or vendor directory and used with a high fidelity <script> tag. Try it out in the console (unless you're on github)!

npm install promissory-arbiter

Here is a quick example to get you started. If you want to see more advanced examples keep on reading. Take a look at the documentation site.

var Arbiter = require('promissory-arbiter');
var log = function(data, topic) {
  console.log(topic, data);
};

Arbiter.subscribe('work.code', log);
Arbiter.subscribe('work', log); // Subscribe to both `work.code` and `work`
Arbiter.subscribe('', log); // Subscribe to all messages
Arbiter.publish('work.code', {type: 'js', duration: 3600});

This library will only work in ES3 browsers if you provide an A+ compatible promise library. If you need one try ES6-promise.

Introduction

Promissory Arbiter is a pure JavaScript implementation of the publish-subscribe or Observer pattern. "Subscribers" subscribe to topics (or messages or channels) and the publishers send these messages or publications when they are ready for them. This allows components to be "loosely" coupled which can lead to more maintainable code, if used correctly.

Promissory Arbiter is asynchronous by default. This means that all subscribers are notified asynchronously of messages. This makes code easier to reason about especially when subscribers fire off additional events. This also lines up with the expectations of most other uses of the callback pattern in JavaScript effectively reducing cognitive load. Since you have been reading a while. Take a break by trying the following code in the console if you are having a hard time understanding what asynchronous means.

Arbiter.subscribe('my.topic', log);
Arbiter.publish('my.topic', data);
console.log('I execute _before_ the subscriber on the first line!');

If you are a synchronous kind of bird, you can set the synchronous option to true. If you try it in the console, remember that you changed it! For a more complete list of options checkout Options.

Arbiter.options.sync = true;

When publishing to the topic "a.b.c", all subscribers to "", "a", "a.b", and "a.b.c" receive the publication in priority order. If a subscriber in "a.b.c" has a higher priority than a subscriber to "", it will be notified before "". The "." separates the topic "generations" and every ancestor of a topic will be notified in addition to original publisher topic. "" is an ancestor of every topic (except itself). Try out the example on the top of the page or read more about topics in the Topics section below.

The last unique feature of promissory-arbiter is "promissory" features. When a publication is made, the publisher gets a promise that it can use to reason about the subscribers. The promise will resolve according to the specified options. By default, when all subscribers are complete the promise fulfills and if any fail, it rejects. This can be changed to allow for a number fulfilled or percent of all subscribers to be fulfilled. You can even relax the promise to be resolved when a number or percent resolves regardless of their success or failure status. In addition to this, it has settings for only running specified number of subscribers at at a time. All of this is documented in the Options section, or randomly guess the options until you have something like the following.

Arbiter.subscribe('get.data', getPeople, {priority: 10});
Arbiter.subscribe('get.data', getPlaces, {priority: 9});
Arbiter.subscribe('get.data', getThings, {priority: 8});
Arbiter.subscribe('get.data', getIdeas, {priority: 7});

// Let's pretend we are in IE7 and we can only have 2 ajax requests at a time.
Arbiter.publish('get.data', null, {semaphor: 2}).then(function(results) {
  // `results` is an array of the people, places, things, and ideas,
  // however only 2 of the subscriptions were ever pending at a time!
}, function(errs) {
  // If any of the publishers fail, you can have the errors here.
});

License

The ISC License

Copyright (c) 2015, Taylor Everding

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.