2016-05-13 56 views
0

我有在一口一個任務來完成,使用一飲而盡-HG,如下:咕嘟咕嘟-HG任務似乎前實際完成

gulp.task('init',['clean'],function(){ 
    return hg.clone('https://myrepo','./deploy',{args:'--insecure'},function(error,stout){ 
     util.log(error); 
    }); 
}); 

顯然吞掉執行依賴於「init」的另一個任務之前,命令完成。我使用回調的方式有問題嗎?

回答

1

您需要遵循的async task patterns之一:

  1. 接受回調
  2. 返回流
  3. 返回一個承諾

在你的榜樣,回調可能是這樣的:

gulp.task('init',['clean'],function(cb){ 
    hg.clone('https://myrepo','./deploy',{args:'--insecure'},function(error,stout){ 
     util.log(error); 
     cb(error); 
    }); 
});