Search code examples
javascriptecmascript-6promisebluebird

(bluebird .tap) Can't return data, do wrong


I do:

 return new bluebird((resolve) => {

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

How to return all data(for each tap) or just last tap in one bluebird wrap.

P.S. I need sequencing (one by one, tap by tap)


Solution

  • .tap explicitly means "ignore the return value", if you need the return value - use the standard .then:

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

    Or more compactly:

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

    Also, you should return the promise chain instead of explicit construction:

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

    Should suffice for the entire body of your function.