This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/js-queue/queue.js

77 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
function Queue(asStack){
Object.defineProperties(
this,
{
add:{
enumerable:true,
writable:false,
value:addToQueue
},
next:{
enumerable:true,
writable:false,
value:run
},
clear:{
enumerable:true,
writable:false,
value:clearQueue
},
contents:{
enumerable:false,
get:getQueue,
set:setQueue
},
autoRun:{
enumerable:true,
writable:true,
value:true
},
stop:{
enumerable:true,
writable:true,
value:false
}
}
);
var queue=[];
var running=false;
var stop=false;
function clearQueue(){
queue=[];
return queue;
}
function getQueue(){
return queue;
}
function setQueue(val){
queue=val;
return queue;
}
function addToQueue(){
for(var i in arguments){
queue.push(arguments[i]);
}
if(!running && !this.stop && this.autoRun){
this.next();
}
}
function run(){
running=true;
if(queue.length<1 || this.stop){
running=false;
return;
}
queue.shift().bind(this)();
}
}
module.exports=Queue;