从不调用async.until函数的迭代器
在Windows10上尝试使用node.js 10.16.0、async 3.0.1 (1809)
const async = require('async');
var counter = 0;
async.until(() => {
console.log('here?')
return (counter > 10)
}, (cb) => {
console.log('not here?');
counter++;
cb()
}, () => {
console.log('the end');
})终端输出
PS C:\Users\hofman\Desktop\Tools\GIT\test> node .
here?
PS C:\Users\hofman\Desktop\Tools\GIT\test>发布于 2019-05-30 19:31:50
test参数应该是异步函数,如下所示
const async = require('async');
var counter = 0;
async.until(async () => {
console.log('here?')
return (counter > 10)
}, (cb) => {
console.log('not here?');
counter++;
cb()
}, () => {
console.log('the end');
})请参阅此处的文档:https://caolan.github.io/async/v3/docs.html#until
或者使用普通的Node风格的异步函数,如下所示
const async = require('async');
var counter = 0;
async.until((cb) => {
console.log('here?')
cb(null, counter > 10)
}, (cb) => {
console.log('not here?');
counter++;
cb()
}, () => {
console.log('the end');
})在版本2.x中,test参数被定义为一个普通的函数https://caolan.github.io/async/v2/docs.html#until
下面是v3.0的Changelog:https://github.com/caolan/async/blob/master/CHANGELOG.md#breaking-changes
whilst、doWhilst、until和doUntil现在具有异步测试函数
https://stackoverflow.com/questions/56377268
复制相似问题