utils: copy over async helpers

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-03-22 16:17:56 +01:00
parent 460306ebe9
commit c2c12542d7

View File

@ -1037,3 +1037,28 @@ utilities: {
me.VlanInterface_match = /(\w+)\.(\d+)/;
},
});
Ext.define('Proxmox.Async', {
singleton: true,
// Returns a Promise resolving to the result of an `API2Request`.
api2: function(reqOpts) {
return new Promise((resolve, reject) => {
delete reqOpts.callback; // not allowed in this api
reqOpts.success = response => resolve(response);
reqOpts.failure = response => {
if (response.result && response.result.message) {
reject(response.result.message);
} else {
reject("api call failed");
}
};
Proxmox.Utils.API2Request(reqOpts);
});
},
// Delay for a number of milliseconds.
sleep: function(millis) {
return new Promise((resolve, _reject) => setTimeout(resolve, millis));
},
});