@paulshorey/

DS Queue

JavaScript

Messing around...

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5736445927231046","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"dmFyIFF1ZXVlID0gZnVuY3Rpb24oKXsKICAKICAvLyBkYXRhCiAgdGhpcy5saXN0ID0gW107CiAgCiAgLy8gcHJpdmF0ZSBhcGkKICB2YXIgdXBsb2FkID0gKGZpbGUpPT57CiAgICAKICAgIC8vIHNpbXVsYXRlIHJhbmRvbSB1cGxvYWQgd2FpdCB0aW1lcwogICAgc2V0VGltZW91dCgoKT0+ewogICAgICB0aGlzLmxpc3Quc3BsaWNlKHRoaXMubGlzdC5pbmRleE9mKGZpbGUpLDEpOwogICAgICBjb25zb2xlLmxvZygiXG51cGxvYWRlZDogIitmaWxlLnBhdGgrJy4uLicsJ3dhaXRpbmcgdG8gdXBsb2FkOiAnLHRoaXMubGlzdCwiXG4iKTsKICAgIH0sTWF0aC5yYW5kb20oKSoxMDAwMCk7CiAgfQogIAogIC8vIHB1YmxpYyBhcGkKICByZXR1cm4gewogICAgZmlsZXNfdXBsb2FkaW5nOiBbXSwKICAgIGZpbGVzX2FkZGVkOiB0aGlzLmxpc3QsCiAgICBmaWxlX2FkZDogZnVuY3Rpb24oZmlsZSl7CiAgICAgIHRoaXMuZmlsZXNfYWRkZWQucHVzaChmaWxlKTsKICAgICAgdXBsb2FkKGZpbGUpOwogICAgfQogICAgCiAgfSAgCgp9Cgp2YXIgdXBsb2FkcyA9IG5ldyBRdWV1ZSgpOwp1cGxvYWRzLmZpbGVfYWRkKHtwYXRoOidraXR0eS5qcGcnfSk7CnVwbG9hZHMuZmlsZV9hZGQoe3BhdGg6J2thdC5naWYnfSk7CnVwbG9hZHMuZmlsZV9hZGQoe3BhdGg6J2dpcmFmZmUuanBnJ30pOwp1cGxvYWRzLmZpbGVfYWRkKHtwYXRoOidzbm9vcC1kb2dneS1kb2dnLm1wMyd9KTs="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var Queue = function(){
  
  // data
  this.list = [];
  
  // private api
  var upload = (file)=>{
    
    // simulate random upload wait times
    setTimeout(()=>{
      this.list.splice(this.list.indexOf(file),1);
      console.log("\nuploaded: "+file.path+'...','waiting to upload: ',this.list,"\n");
    },Math.random()*10000);
  }
  
  // public api
  return {
    files_uploading: [],
    files_added: this.list,
    file_add: function(file){
      this.files_added.push(file);
      upload(file);
    }
    
  }  

}

var uploads = new Queue();
uploads.file_add({path:'kitty.jpg'});
uploads.file_add({path:'kat.gif'});
uploads.file_add({path:'giraffe.jpg'});
uploads.file_add({path:'snoop-doggy-dogg.mp3'});
Native Browser JavaScript