首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >async until不进入iteratee (async 3.0.1)

async until不进入iteratee (async 3.0.1)
EN

Stack Overflow用户
提问于 2019-05-30 19:18:08
回答 1查看 458关注 0票数 0

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

在Windows10上尝试使用node.js 10.16.0、async 3.0.1 (1809)

代码语言:javascript
复制
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');
})

终端输出

代码语言:javascript
复制
PS C:\Users\hofman\Desktop\Tools\GIT\test> node .
here?
PS C:\Users\hofman\Desktop\Tools\GIT\test>
EN

回答 1

Stack Overflow用户

发布于 2019-05-30 19:31:50

test参数应该是异步函数,如下所示

代码语言:javascript
复制
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风格的异步函数,如下所示

代码语言:javascript
复制
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现在具有异步测试函数

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56377268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档