Javascript 蓝鸟承诺库:是否.map和.filter并行运行?

Javascript 蓝鸟承诺库:是否.map和.filter并行运行?,javascript,performance,node.js,parallel-processing,bluebird,Javascript,Performance,Node.js,Parallel Processing,Bluebird,我正试图在中编写一组异步fs调用。这一切都很好,除了我担心性能。我不知道.map和.filter函数是并行执行还是顺序执行。这是我的密码: var Promise = require('bluebird'), fs = Promise.promisifyAll(require('fs')); module.exports = getDirListing; function getDirListing(path) { function toFullPath(file) { re

我正试图在中编写一组异步
fs
调用。这一切都很好,除了我担心性能。我不知道
.map
.filter
函数是并行执行还是顺序执行。这是我的密码:

var Promise = require('bluebird'),
  fs = Promise.promisifyAll(require('fs'));

module.exports = getDirListing;

function getDirListing(path) {
  function toFullPath(file) {
    return path + file;
  }
  function onlyDirs(file) {
    return fs.statAsync(file).then(function(file) {
      return !file.isFile();
    });
  }
  function ignoreHidden(name) {
    return !(name.substring(0,1) === '.');
  }
  function toModuleNames(dir) {
    return dir.replace(path, '');
  }
  return fs.readdirAsync(path)
    .map(toFullPath)
    .filter(onlyDirs)
    .map(toModuleNames)
    .filter(ignoreHidden);
}
我特别关心对
onlyDirs
的调用,因为这会产生一系列异步
fs.stat
调用,并且可以/应该是并行的。我试着看了一下,但没有看到任何关于并行化的内容

注意:我目前无法使用ECMAScript 6生成器(很遗憾)


此外,欢迎在此处提供有关性能的任何其他指针。

fs.stat调用是同时完成的,您可以使用以下方法进行验证:

var id = 0;
function onlyDirs(file) {
  var d = id++;
  return fs.statAsync(file).then(function(file) {
    console.log("returned from stat call %d", d);
    return !file.isFile();
  });
}
注意:代码最初不起作用,我不得不修改:

var Path = require("path");
function toFullPath(file) {
    return Path.join(path, file);
}
var Path = require("path");
function toFullPath(file) {
    return Path.join(path, file);
}