Promise超时重新请求
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);
});
}
Promise超时重新请求的更多相关文章
- axios请求拦截及请求超时重新请求设置
自从使用Vue2之后,就使用官方推荐的axios的插件来调用API,在使用过程中,需要解决问题: 1. 请求带token校验 2. post请求请求体处理 3. 响应未登录跳转登录页处理 4. 响应错 ...
- React Native 网络请求封装:使用Promise封装fetch请求
最近公司使用React作为前端框架,使用了异步请求访问,这里做下总结: React Native中虽然也内置了XMLHttpRequest 网络请求API(也就是俗称的ajax),但XMLHttpRe ...
- 封装fetch请求失败和超时再次请求
转: 封装fetch请求失败和超时再次请求 function _fetch(fetch_promise, timeout) { var abort_fn = null; //这是一个可以被reject ...
- Angular JS 学习笔记(自定义服务:factory,Promise 模式异步请求查询:$http,过滤器用法filter,指令:directive)
刚学没多久,作了一个小项目APP,微信企业号开发与微信服务号的开发,使用的是AngularJS开发,目前项目1.0版本已经完结,但是项目纯粹为了赶工,并没有发挥AngularJS的最大作用,这几天项目 ...
- 基于 Promise 的 HTTP 请求客户端 axios
基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中使用 功能特性 在浏览器中发送 XMLHttpRequests 请求 在 node.js 中发送 http请求 支持 ...
- vue axios----基于 Promise 的 HTTP 请求
vue axiosvue2.0之axios接口請求管理功能特性axios API開始使用get請求post请求多个请求并发拦截器移除一个拦截器:自定义的 axios 实例添加拦截器:vue2.0之ax ...
- ES6 promise 封装http请求
今天研究了一下同事封装的http请求,用的是promise. 大结构是: const __fetch = (url, data = {}, config = {}) => { let param ...
- 配置SESSION超时与请求超时
<!--项目的web.xml中 配置SESSION超时,单位是min.用户在线时间.如果不设置,tomcat下的web.xml的session-timeout为默认.--><sess ...
- 解决spring-security session超时 Ajax 请求没有重定向的问题
开始时, 代码是这样的: $.ajax({ type : "POST", url : sSource, cache : false, dataType : "json&q ...
随机推荐
- Python类(二)-类的继承
单继承 #-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" class People: def __init__(self,name ...
- 黑客工具包ShadowBrokers浅析
臭名昭著的方程式组织工具包再次被公开,TheShadowBrokers 在 steemit.com博客上提供了相关消息. 本次被公开的工具包大小为117.9MB,包含23 个黑客工具,其中部分文件显示 ...
- 关于jquery在页面初始化时radio控件选定默认值的问题
网上找了很多资料,都是比较旧版本的方法,新版的jquery都已经抛弃了. 正确的代码是 $('input:radio[name="statusRadios"][value=&quo ...
- Spring MVC的配置
一.添加依赖 <dependency> <groupId>org.springframework</groupId> <artifactId>sprin ...
- java基础之JDBC八:Druid连接池的使用
基本使用代码: /** * Druid连接池及简单工具类的使用 */ public class Test{ public static void main(String[] args) { Conne ...
- NFA/DFA算法
1.问题概述 随着计算机语言的结构越来越复杂,为了开发优秀的编译器,人们已经渐渐感到将词 法分析独立出来做研究的重要性.不过词法分析器的作用却不限于此.回想一下我们的老师刚刚开始向我们讲述程序设计的时 ...
- rsync 服务器架设方法
作者: 北南南北 来自:Linuxsir.Org 摘要: rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用.本文主要讲述的是如何自 ...
- javascript-文档结构遍历
1.document.all document.all[0] //文档中第一个元素 document.all["navbar"] //id或name为"navbar&qu ...
- PrimeNG01 angular集成PrimeNG
1 开发环境 本博文基于angular5 2 步骤 2.1 创建angular5项目 详情参见百度 2.2 下载PrimeNG依赖 npm install primeng --save npm ins ...
- 1-element.src.match("bulbon")
element.src.match("bulbon")这里的math里面”bulbon“是什么意思? 原代码中 if (element.src.match("bulbon ...