Is Node.js Array.map() asynchronous?

前端 未结 6 1257
遥遥无期
遥遥无期 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 13:51

    This function is synchronous - otherwise it couldn't return the result of the map operation.

    Any callbacks that might take longer time (mainly due to IO) are asynchronous in nodejs - unless the method is explicitely marked as being synchronous (such as fs.readFileSync - but that doesn't use a callback). You probably confused that somehow.

提交回复
热议问题