(蓝鸟.tap)无法返回数据,做错了

问题描述:

我做的:(蓝鸟.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

.tap明确表示“忽略返回值”,如果你需要的返回值 - 使用标准.then

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

或者更简洁:

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

此外,你应该return许链,而不是explicit construction

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

应该足够您的功能的整个身体。