finally.js 345 B

12345678910111213141516
  1. 'use strict';
  2. var Promise = require('./core.js');
  3. module.exports = Promise;
  4. Promise.prototype.finally = function (f) {
  5. return this.then(function (value) {
  6. return Promise.resolve(f()).then(function () {
  7. return value;
  8. });
  9. }, function (err) {
  10. return Promise.resolve(f()).then(function () {
  11. throw err;
  12. });
  13. });
  14. };