javascript - 如何根据重试次数重复迭代
问题描述
我正在将文件块上传到 Dropbox,我需要在循环中添加一个简单的重试。因此,如果第一次尝试失败,请在放弃之前再重试 2 次。
给出一些上下文。我将文件分块上传到 Dropbox。但是,我需要让脚本优雅地失败。在我终止上传并给用户一个错误之前,要求脚本重复上传 3 次。
例如(不是实际尝试只是一个概念):
var retries = 3;
jQuery(dropbox.chunks).each(function(index, chunk){
var result = anothingFunction();
if (result == true) {
//continue the loop
}
if (result == false) {
retries--;
if (retries > 0) {
//Retry this iteration
}
if (retries = 0) {
//Kill the entire loop as this upload clearly is not going to happen.
}
}
}
解决方案
推荐阅读
- java - 使用蓝牙打印机打印时位图看起来严重倾斜
- c# - ITextSharp PdfCleanUpProcessor 类清理方法已删除整行
- python - GeoJson 和传单
- simulation - AnyLogic_Parking_Simulation
- python - 如何模拟由'__init__'的方法调用的方法
- java - 在接口 VS 中定义的匿名类。接口外的具体类
- python - 如何在列中仅放置部分字符串值?
- excel - Excel VBA,比较两个不同列中的值并保留整行以获得共同值
- javascript - 尝试使用 getElementById 更改 innerHTML 时,ng-repeat 不起作用
- arduino - 错误:没有匹配函数调用 'UdpContext::listen(const ip_addr_t&, int&)' if(!_udp_ota->listen(*IP_ADDR_ANY, _port))