簡體   English   中英

Node.js async.whilst()根本沒有執行

[英]Node.js async.whilst() is not executing at all

我只是想用async.whilst()所看到這里

這是我的簡單代碼,取自他們的文檔:

var async = require('async');

console.log('start');
async.whilst(
  function () { return true; },
  function (callback) {
    console.log('iteration');
    callback();
  },
  function (err) {
    console.log('end');
  },
);

當我運行它時,循環不會運行。 start打印。

因為返回的是true,所以未調用函數1的回調。 因此,您只會看到“開始”。 您可以在下面找到一些信息:

  const async = require('async'); let count = 0; const compareVariable = 10; console.log('start'); async.whilst( function functionName1(callbackFunction) { // perform before each execution of iterFunctionInside, you need a condition(or other related condition) in 2nd params. callbackFunction(null, count < compareVariable) }, // this func is called each time when functionName1 invoked function iterFunctionInside(callback) { // increase counter to compare with compareVariable count++; console.log('iteration', count); // if you want to show like tick time, you can set timeout here or comment out if you dont want setTimeout(() => { callback(null, count); }, 1000) }, function (err, n) { console.log('end'); }, ); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM