Ok, i found a solution using async functions. Now you can use "mySleep(time in ms)" in every async function in your project. The only addition is, that you need a check, that the async function is only called once (see global variable: "g_active"):
// global variable, could also be stored in an object
let g_active = true;
function Tick(runtime)
{
if(g_active) demoFunction();
}
function mySleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demoFunction() {
g_active = false;
console.log('start');
await mySleep(2000);
console.log('two seconds later');
await mySleep(2000);
console.log('four seconds later');
await mySleep(2000);
g_active = true;
}