使用节点确定成功/失败.js函数 async.retry
Determining success/failure with node.js function async.retry
我正在研究node.js模块异步,但我对函数async.retry有一些问题。
根据其github文档,该函数将继续尝试该任务,直到成功或机会用完。但是我的任务如何判断成功或失败?
我尝试了下面的代码:
var async = require('async');
var opts = {
count : -3
};
async.retry(5, function (cb, results) {
++this.count;
console.log(this.count, results);
if (this.count > 0) cb(null, this.count);
else cb();
}.bind(opts), function (err, results) {
console.log(err, results);
});
我希望它运行到 count === 1
,但它总是打印以下内容:
-2 undefined
undefined undefined
那么如何才能正确使用该功能呢?
您希望else
分支失败。为此,您需要向错误参数传递一些内容;目前,你只是传递undefined
这标志着成功 - 这就是你得到的回报。
async.retry(5, function (cb, results) {
++this.count;
console.log(this.count, results);
if (this.count > 0) cb(null, this.count);
else cb(new Error("count too low"));
}.bind(opts), function (err, results) {
console.log(err, results);
});
相关文章:
- PHP和JS脚本的奇怪问题,在我刷新页面之前第一次失败
- 使用Office.js在Excel中将20000多个单元格写入表失败
- scrypt.js失败,N大于2^14
- 解析JS SDK登录到Node.JS中运行的解析服务器=失败
- JS:执行'失败;getComputedStyle'在'窗口':参数的类型不是'
- 使用Q节点模块时,Bluemix node.js应用程序部署失败
- fs.readFileSync()在express js应用程序中失败
- 如何允许Dropzone.js失败后重新提交文件上传
- JS失败,除非控制台打开
- 节点中的 CORS 问题.js失败
- Jenkins sonar build使用js失败
- 通过请求从代码中获取 Dropbox OAuth 令牌.js失败;等效卷曲工作
- 使用bootstrap-carousel.js失败
- 滚动到一个元素使用js失败在我的情况下
- 扩展sap.m.List给了我错误:加载'sap/m/items.js'失败
- 时间序列与plot .js失败,w/ fiddle
- 拉斐尔JS失败了
- 关键错误插入到MongoDB使用node.js失败的一些对象没有任何键包含一个点
- 添加自定义标记图片的传单 js 失败
- 在OS X 10.8.2上构建ember.js失败