Is there a way to stop execution of next function of series with async in nodejs?

前端 未结 4 1002
深忆病人
深忆病人 2021-02-14 06:13
  async.map(list, function(object, callback) {
    async.series([
      function(callback) {
        console.log(\"1\");

        var booltest = false;
        // assumi         


        
4条回答
  •  礼貌的吻别
    2021-02-14 06:59

    I think the function you are looking for is async.detect not map.

    from https://github.com/caolan/async#detect

    detect(arr, iterator, callback)

    Returns the first value in arr that passes an async truth test. The iterator is applied in parallel, meaning the first iterator to return true will fire the detect callback with that result. That means the result might not be the first item in the original arr (in terms of order) that passes the test.

    example code

    async.detect(['file1','file2','file3'], fs.exists, function(result){
        // result now equals the first file in the list that exists
    });
    

    You could use that with your booltest to get the result you want.

提交回复
热议问题