SOURCE

const sleep = time => {
    return new Promise(resolve => setTimeout(resolve, time));
}

let p = async (overtime, fn) => {
    window._StartTime = window._StartTime ?? new Date();
    await sleep(200);
    var result = fn.call();
    console.log(result);
    if (!result) {
        var t = new Date();
        var d = t - _StartTime;
        if (d > overtime) {
            window._StartTime = null;
            return 'OverTime';
        }
        else {
            return p(overtime, fn);
        }
    }
    else {
        window._StartTime = null;
        return result;
    }
}


let num = 0;

p(3000, () => {
    num++;
    if (num > 30) {
        return num;
    }
    else {
        return null;
    }
}).then(result => console.log(result))
console 命令行工具 X clear

                    
>
console