Added an async method to wait X seconds (max) for a callback to return true

This commit is contained in:
Niko 2022-02-18 11:25:34 +01:00
parent c39fc40196
commit 19567fadd9
1 changed files with 9 additions and 0 deletions

View File

@ -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\.\_]+$/))