异步直到不输入iteratee(异步3.0.1)

时间:2019-05-30 11:18:08

标签: node.js async.js

从不调用async.until函数的迭代器

在Windows 10(1809)上尝试使用node.js 10.16.0,异步3.0.1

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>

1 个答案:

答案 0 :(得分:0)

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');
})

在此处查看文档:{​​{3}}

或使用普通的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/v3/docs.html#until

以下是v3.0的变更日志: https://caolan.github.io/async/v2/docs.html#until

  

现在,doWhilst,直到和doUntil现在都具有异步测试功能