为什么async.series在REPL中不能用于下面的代码?

时间:2013-06-21 14:29:50

标签: node.js asynchronous concurrency

         request(source_url).pipe(async.series([
             function() {
               fs.createWriteStream(path_for_downloads + path.basename(source_url));
             },
             function() {
               done(null);
             }
           ]);
         );

它等待未关闭的括号...

...              );
... 

这有效:

async.series([
                 function() {
                   fs.createWriteStream(path_for_downloads + path.basename(source_url));
                 },
                 function() {
                   done(null);
                 }
               ]);

1 个答案:

答案 0 :(得分:2)

request(source_url).pipe(async.series([
         function() {
           fs.createWriteStream(path_for_downloads + path.basename(source_url));
         },
         function() {
           done(null);
         }
       ]); //close the array, close async.series call, OOPS don't want a semi there
     ); //close the pipe call

我认为这是你的错误。但是,这个片段还有许多其他问题。我想你想要更像的东西:

var stream = request(source_url).pipe(fs.createWriteStream(path_for_downloads + path.basename(source_url));
stream.on('end', done);
stream.on('error', done);