2017-10-09 35 views
0

我做的:(藍鳥.tap)無法返回數據,做錯了

return new bluebird((resolve) => { 
 

 
    bluebird.resolve() 
 
    .tap(saveExcelFiles) 
 
    .tap(...) 
 
    .tap(() => { 
 
     return getZip().then((rows) => { 
 
     resolve(rows) // this outer bluebird helps me 
 
     return rows; 
 
     }); 
 
    }) 
 
    ; 
 
    
 
});

如何返回一個藍鳥包裝的所有數據(每個水龍頭)或者就在上個星期自來水。

P.S.我需要測序(一個接一個,自來水用自來水)

+0

@alexmac,你可以改進一些例子嗎? – aaaaaaaaax10

+0

避免['Promise' constructor antipattern](https://stackoverflow.com/q/23803743/1048572?What-is-the-promise-construction-antipattern-and-how-to-avoid-it)! – Bergi

回答

2

.tap明確表示「忽略返回值」,如果你需要的返回值 - 使用標準.then

.then(() => { 
    return getZip().then((rows) => { 
    // Nothing outer. 
    return rows; 
    }); 
}); 

或者更簡潔:

.then(getZip); // that's it! 

此外,你應該return許鏈,而不是explicit construction

return saveExcelFiles().tap(...).then(getZip); 

應該足夠您的功能的整個身體。