Is Node.js Array.map() asynchronous?

前端 未结 6 1264
遥遥无期
遥遥无期 2020-12-24 13:10

Can I count on nodeIDs mapping is completed every time doSomething() is called?

nodeIDs = $.map(nodeIDs, function(n){
    return n.match(/\\d+$/);
});
doSome         


        
6条回答
  •  盖世英雄少女心
    2020-12-24 14:15

    import the async module to have an asynchronous 'map' method

    var async = require('async');
    
    var arr = ['1','2'];
    async.map(arr, getInfo, function (e, r) {
      console.log(r);
    });
    
    function getInfo(name, callback) {
      setTimeout(function() {
        callback(null, name + 'new');
      }, 1000);
    }
    

提交回复
热议问题