Skip to content
/ buzy Public
forked from subbu963/buzy

Async queue manager for node and browser

License

Notifications You must be signed in to change notification settings

ptzagk/buzy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buzy

Async queue manager for node and browser.

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.

Installation

$ npm install buzy

Usage

import Buzy from 'buzy';

const buzy1 = new Buzy;
const buzy2 = new Buzy([function(message) {
  console.log(message);
}], [buzy1]);

buzy1.addPromise(new Promise(function(resolve, reject) {
  setTimeout(function() {
    resolve('done');
  }, 1000);
}))

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 is a buzy is busy or not:

buzy.isBusy() //true or false

To do

  1. Cancellation of requests
  2. You tell me!

About

Async queue manager for node and browser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%