Commit eab844af authored by Evgeny's avatar Evgeny

Buffer add finishAll method

parent efde3872
......@@ -117,6 +117,23 @@
};
/**
* Resolves while buffer is not empty, but not more than 10 times.
* @function finishAll
* @returns {int} How many times 'finish' was called
*/
Buffer.prototype.finishAll = function(){
var self = this;
var counter = 0;
while(!self.isEmpty() && counter<10){
self.finish();
counter++;
}
return counter;
};
/**
* Adds callback to main queue and starts timer
* @function onfinish
* @param {Function} callback
......@@ -161,6 +178,21 @@
return isUndefined(self.namedCallbacks[id]);
};
Buffer.prototype.isEmpty = function(){
var self = this;
for(var id in self.namedCallbacks){
if(self.has(id)){
return false;
}
}
var callbacks = self.callbacks.length == 0;
var lastCallbacks = self.lastCallbacks.length == 0;
return callbacks && lastCallbacks;
};
/**
* Sets timeout after which buffer should fire
* @function setTimeout
......
......@@ -112,6 +112,23 @@ Buffer.prototype.finish = function(){
};
/**
* Resolves while buffer is not empty, but not more than 10 times.
* @function finishAll
* @returns {int} How many times 'finish' was called
*/
Buffer.prototype.finishAll = function(){
var self = this;
var counter = 0;
while(!self.isEmpty() && counter<10){
self.finish();
counter++;
}
return counter;
};
/**
* Adds callback to main queue and starts timer
* @function onfinish
* @param {Function} callback
......@@ -156,6 +173,21 @@ Buffer.prototype.has = function(id){
return isUndefined(self.namedCallbacks[id]);
};
Buffer.prototype.isEmpty = function(){
var self = this;
for(var id in self.namedCallbacks){
if(self.has(id)){
return false;
}
}
var callbacks = self.callbacks.length == 0;
var lastCallbacks = self.lastCallbacks.length == 0;
return callbacks && lastCallbacks;
};
/**
* Sets timeout after which buffer should fire
* @function setTimeout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment