倒计时时长(毫秒)
返回一个闭包函数,闭包返回的是倒计时,倒计时最小为0,不会是负数
const timeout = 500;
const timeCountDown = createTimeCountDown(timeout);
await sleep(50);
let t1 = timeCountDown();
timeout - 150 <= t1 && t1 <= timeout - 50; // true
await sleep(150);
t1 = timeCountDown();
timeout - 300 <= t1 && t1 <= timeout - 200; // true
await sleep(350);
timeCountDown(); // 0
t1.pause(); // 暂停
t1.play(); // 继续
创建一个倒计时闭包函数