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

buzy

v0.1.5

Published

Async queue manager for node and browser

Downloads

3

Readme

buzy

Promise based async queue manager for node and browser.

Buzy is a blackbox into which you push promises and at each point in time you can know if any of the promises are still in pending state(busy state). Optionally you can subscribe for the event bus which will let you know when there is change in the blackbox state

Its particularly useful where you want to know if your system is busy with async activities like ajax calls etc. You can push promises in to the queue and buzy will do the job of letting you know when the state of the system changes. Use cases can be:

  1. Show loaders on ajax calls
  2. Check if any of your tasks are pending before closing the browser and similar others

Installation

$ npm install buzy

Syntax

new Buzy(subscribers, buzies);
  • subscribers - array of functions which will be called upon the change when there is a state change or when a promise is resolved/reject(this wont be triggered for buzies dependent on other buzies)
  • buzies - array of buzies to subscribe on to

Subscribers will be called with the following message data structure

{
    code: number, // 0 - STATE change, 1 - RESOLVE, 2 - REJECT
    busy: true/false,
    promise: promise, //promise which is last resolved/rejected
    value: value, // value of the resolution
    error: error // error of the rejection
}

New promises can be added with:

buzy.addPromise(promise) //single promise
buzy.addPromises(promises) //array of promises

New subscribers can be added with:

buzy.addSubscriber(subscriber) //single subscriber
buzy.addSubscribers(subscribers) //array of subscribers

New buzies can be added with:

buzy.addBuzy(buzy) //single buzy
buzy.addBuzies(buzies)//array of buzies

To check if buzy is busy or not:

buzy.isBusy() //true or false

Examples

import Buzy from 'buzy';

const buzy1 = new Buzy([function(message) {
  console.log(message);
   /*
      Prints the following:
      {
          code: 0,
          busy: true
      }
      And after 1000 milliseconds
      {
          code: 1,
          promise: Promise{'done'},
          value: 'done'
      }
      And then
      {
          code: 0,
          busy: false
      }
    */
}]);
const buzy2 = new Buzy([function(message) {
  console.log(message);
  /*
    Prints the following:
    {
        code: 0,
        busy: true
    }
    And after fetch is complete
    {
        code: 1 or 2 based on fetch result,
        promise: Promise{res from fetch},
        value: value or error: error based fetch result
    }
    And then after buzy1 is done with all the tasks
    {
        code: 0,
        busy: false
    }
  */
}], [buzy1]);

buzy1.addPromise(new Promise(function(resolve, reject) {
  setTimeout(function() {
    resolve('done');
  }, 1000);
}))
buzy2.addPromise(fetch('http://someurl'));

Check Buzy.test.js for more exmaples

To do

  1. Cancellation of promises
  2. Removal of subscribers/buzies
  3. You tell me!