export default function (promiseProducer, params, interval, attemptTimes) { interval = typeof interval === "number" && interval >= 300 ? interval : 500; attemptTimes = typeof attemptTimes === "number" && attemptTimes >= 1 ? attemptTimes : 10000; return new Promise((resolve, reject) => { let promise = null; let executePromise = timer => { if(attemptTimes < 1){ window.clearInterval(timer); reject(new Error('promise not until timeout')); return void 0; } attemptTimes -= 1; return promiseProducer(params).then(res => { window.clearInterval(timer); resolve(res); }).catch((e) => { throw new Error(e); }); }; let timer = window.setInterval(() => { promise = executePromise(timer); }, interval); promise = executePromise(timer); }); }