import extend from "./extend";

/**
 * 睡眠
 * @param {number} time 睡眠时间（毫秒）
*/
async function sleep (time) {
    if (extend.isNumber(time)) {
        time = 0;
    }
    return new Promise((resolve, reject) => {
        if (time <= 0) {
            resolve();
        }
        let timer = setTimeout(() => {
            resolve();
            clearTimeout(timer);
        }, time);
    });
}