squadron

1.0.0 • Public • Published

squadron

Circle CI Greenkeeper badge

Synchronize, throttle and debounce promises

Installation

npm install squadron

Synchronizer

The Synchronizer can be used to synchronize any set of promises. It can be very useful when you need to ensure sequential ordering. It can also be used to implement a mutex around a resource as it ensures that only one promise can access the resource concurrently.

var squadron = require('squadron'),
  sporks = require('sporks');
 
var testPromise = function (milliseconds, name) {
  console.log('begin', name);
  return sporks.timeout(milliseconds).then(function () {
    console.log('end', name);
    return name;
  });
};
 
var synchronizer = new squadron.Synchronizer();
 
synchronizer.run(function () {
  return testPromise(200, 'promise 1');
});
 
synchronizer.run(function () {
  return testPromise(100, 'promise 2');
});

The output is then

begin promise 1
end promise 1
begin promise 2
end promise 2

TODO: Throttler

TODO: Debouncer

Readme

Keywords

none

Package Sidebar

Install

npm i squadron

Weekly Downloads

119

Version

1.0.0

License

MIT

Unpacked Size

35.7 kB

Total Files

22

Last publish

Collaborators

  • redgeoff