mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-05-03 02:54:17 +00:00
utils: copy over async helpers
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
460306ebe9
commit
c2c12542d7
25
src/Utils.js
25
src/Utils.js
@ -1037,3 +1037,28 @@ utilities: {
|
|||||||
me.VlanInterface_match = /(\w+)\.(\d+)/;
|
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));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user