pve-manager/www/manager/data/UpdateQueue.js
2011-08-23 07:40:22 +02:00

48 lines
824 B
JavaScript

// Serialize load (avoid too many parallel connections)
Ext.define('PVE.data.UpdateQueue', {
singleton: true,
constructor : function(){
var me = this;
var queue = [];
var queue_idx = {};
var idle = true;
var start_update = function() {
if (!idle) {
return;
}
var store = queue.shift();
if (!store) {
return;
}
queue_idx[store.storeid] = null;
idle = false;
store.load({
callback: function(records, operation, success) {
idle = true;
start_update();
}
});
};
Ext.apply(me, {
queue: function(store) {
if (!store.storeid) {
throw "unable to queue store without storeid";
}
if (!queue_idx[store.storeid]) {
queue_idx[store.storeid] = store;
queue.push(store);
}
start_update();
}
});
}
});