finally.js 348 B

1234567891011121314151617
  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. };