index.js 302 B

12345678910111213141516
  1. 'use strict';
  2. module.exports = (promise, onFinally) => {
  3. onFinally = onFinally || (() => {});
  4. return promise.then(
  5. val => new Promise(resolve => {
  6. resolve(onFinally());
  7. }).then(() => val),
  8. err => new Promise(resolve => {
  9. resolve(onFinally());
  10. }).then(() => {
  11. throw err;
  12. })
  13. );
  14. };