]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - data/UpdateQueue.js
bump version to 1.0-7
[proxmox-widget-toolkit.git] / data / UpdateQueue.js
CommitLineData
0bb29d35
DM
1// Serialize load (avoid too many parallel connections)
2Ext.define('Proxmox.data.UpdateQueue', {
3 singleton: true,
4
5 constructor : function(){
6 var me = this;
7
8 var queue = [];
9 var queue_idx = {};
10
11 var idle = true;
12
13 var start_update = function() {
14 if (!idle) {
15 return;
16 }
17
18 var storeid = queue.shift();
19 if (!storeid) {
20 return;
21 }
22 var info = queue_idx[storeid];
23 queue_idx[storeid] = null;
24
25 info.updatestart = new Date();
26
27 idle = false;
28 info.store.load({
29 callback: function(records, operation, success) {
30 idle = true;
31 if (info.callback) {
32 var runtime = (new Date()).getTime() - info.updatestart.getTime();
33 info.callback(runtime, success);
34 }
35 start_update();
36 }
37 });
38 };
39
40 Ext.apply(me, {
41 queue: function(store, cb) {
42 var storeid = store.storeid;
43 if (!storeid) {
44 throw "unable to queue store without storeid";
45 }
46 if (!queue_idx[storeid]) {
47 queue_idx[storeid] = {
48 store: store,
49 callback: cb
50 };
51 queue.push(storeid);
52 }
53 start_update();
54 },
55 unqueue: function(store) {
56 var storeid = store.storeid;
57 if (!storeid) {
58 throw "unabel to unqueue store without storeid";
59 }
60 if (queue_idx[storeid]) {
61 Ext.Array.remove(queue,storeid);
62 queue_idx[storeid] = null;
63 }
64 }
65 });
66 }
67});