- Complete React app with 7 developer tools - JSON Tool with visual structured editor - Serialize Tool with visual structured editor - URL, Base64, CSV/JSON, Beautifier, Diff tools - Responsive navigation with dropdown menu - Dark/light mode toggle - Mobile-responsive design with sticky header - All tools working with copy/paste functionality
38 lines
779 B
JavaScript
38 lines
779 B
JavaScript
'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;
|