Sha256: 5cc7720faec4af9c444e1ed3685bb14e9425169322895b6be4fc4333d2adddb4

Contents?: true

Size: 779 Bytes

Versions: 38

Compression:

Stored size: 779 Bytes

Contents

'use strict';

var RingBuffer = require('./ring_buffer');

var Pledge = function() {
  this._complete  = false;
  this._callbacks = new RingBuffer(Pledge.QUEUE_SIZE);
};

Pledge.QUEUE_SIZE = 4;

Pledge.all = function(list) {
  var pledge  = new Pledge(),
      pending = list.length,
      n       = pending;

  if (pending === 0) pledge.done();

  while (n--) list[n].then(function() {
    pending -= 1;
    if (pending === 0) pledge.done();
  });
  return pledge;
};

Pledge.prototype.then = function(callback) {
  if (this._complete) callback();
  else this._callbacks.push(callback);
};

Pledge.prototype.done = function() {
  this._complete = true;
  var callbacks = this._callbacks, callback;
  while (callback = callbacks.shift()) callback();
};

module.exports = Pledge;

Version data entries

38 entries across 37 versions & 14 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.18.0 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.18.2 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.16.1 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.15.2 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.18.4 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.18.1 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.14.0 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
tang-0.2.1 spec/tang_app/node_modules/websocket-extensions/lib/pipeline/pledge.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/websocket-extensions/lib/pipeline/pledge.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/websocket-extensions/lib/pipeline/pledge.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/websocket-extensions/lib/pipeline/pledge.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/websocket-extensions/lib/pipeline/pledge.js
tang-0.2.0 spec/tang_app/node_modules/websocket-extensions/lib/pipeline/pledge.js
tang-0.1.0 spec/tang_app/node_modules/websocket-extensions/lib/pipeline/pledge.js
tang-0.0.9 spec/tang_app/node_modules/websocket-extensions/lib/pipeline/pledge.js
enju_library-0.3.8 spec/dummy/node_modules/websocket-extensions/lib/pipeline/pledge.js
ilog-0.4.1 node_modules/websocket-extensions/lib/pipeline/pledge.js