export const ERROR_PROMISE_TIMEOUT = ‘ERROR_PROMISE_TIMEOUT‘; export default function (promise, timeout) { let timer = undefined; return Promise.race([ new Promise(function (resolve, reject) { timer = setTimeout(() => { reject(new Error(ERROR_PROMISE_TIMEOUT)); }, timeout) }), promise.then(res => { timer && window.clearTimeout(timer); return res; }).catch(err => { timer && window.clearTimeout(timer); return Promise.reject(err); }) ]) }
原文地址:https://www.cnblogs.com/rusr/p/9983711.html
时间: 2024-10-31 04:26:36