sindresorhus / p-map

Map over promises concurrently
MIT License
1.27k stars 58 forks source link

.finally does not work for me with pMap #9

Closed revelt closed 6 years ago

revelt commented 6 years ago

hi Sindre, guys,

Whenever I append .finally I get this error message: TypeError: pMap(...).catch(...).finally is not a function

For example, here I try to write bunch of files asynchronously:

const fs = require("fs-extra");
const pMap = require("p-map");
// ...
pMap(filesToWrite, oneToDoObj => {
    fs
      .outputFile(
        oneToDoObj.name,
        resolveVars(oneToDoObj.contents)
      )
      .then(log(chalk.green(logSymbols.success, oneToDoObj.name)));
  })
    .then(() => {
      step2();
    })
    .catch(err => {
      log(`${chalk.red(logSymbols.error, `error writing file:\n${err}`)}`);
      step2();
    })
    .finally(() => {
      console.log("finally");
    });

The code above does work without the last .finally step. It's as if .finally was not allowed. By the way, me calling step2() and not returning promise above is not an issue, I tried returning Promise.resolve()'d function, same thing - works without .finally, doesn't with it.

Did you ever try .finally on pMap and did it work for you?

Thank you.

sindresorhus commented 6 years ago

.finally() is not yet available in Node.js: http://node.green/#ES2018-features-Promise-prototype-finally

revelt commented 6 years ago

aha! Thanks for prompt response.