简体   繁体   中英

Trying to write alternative for promise.allsettled using async.each

I earlier had a code with Promise.allSettled(payoutPromises);

But it couldn't work on our server because it has a version 10 for nodejs.

This is what I came up with to do something similar, using some blogs as reference.

  async.each(transactions, function(transaction, iteratorCB) {
    payoutPromises.push(function(callback) {
      ValidationHelper.bankPayoutTransfer(transaction, 'neft').then((data) => {
        response.push({"status":"fulfilled","value":data});
        callback(null, data);
      }).catch((_err) => {
        response.push({"status":"rejected","reason":_err});
      });
    });
    iteratorCB();
  }, function() {
    async.parallel(payoutPromises, function(err, results) {
      console.log(err,results);
    });
  })

The problem I am facing is I want to wait for this async block before executing the rest of the code, like we can using a then after Promise.allSettled I am a noob in terms of nodejs and working on it since a year.

Posting my comment as an answer:

Try implementing this module . It seems to be pretty popular and it does the thing you want to implement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM