Added an async method to wait X seconds (max) for a callback to return true
This commit is contained in:
parent
c39fc40196
commit
19567fadd9
|
@ -121,6 +121,15 @@ function loadScript(id, file, cback) {
|
|||
function getNormalizedURI() { return window.location.pathname.replace(/\/+?$/, '') }
|
||||
function capitalize(s) { return s.charAt(0).toUpperCase() + s.substr(1) }
|
||||
function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)) }
|
||||
async function waitUntil(cback, secs) {
|
||||
var i = 0;
|
||||
while (i < secs) {
|
||||
if (cback())
|
||||
return;
|
||||
await sleep(1000);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
function s(name) {
|
||||
if (app.strings === undefined || !name.match(/^[a-zA-Z0-9\.\_]+$/))
|
||||
|
|
Loading…
Reference in New Issue