SOURCE

//请求某个图片资源
function requestImg() {
    var p = new Promise((resolve, reject) => {
        var img = new Image();
        img.onload = function() {
            resolve(img);
        }
        img.src = '图片的路径';
    });
    return p;
}

function timeout() {
    var p = new Promise((resolve, reject) => {
        setTimeout(() => {
            reject('图片请求超时');
        }, 5000);
    });
    return p;
}

Promise.race([requestImg(), timeout()]).then(data) => {
    console.log(data);
}.catch((err) => {
    console.log(err);
})
console 命令行工具 X clear

                    
>
console