Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

direct_resolve.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. module.exports = function(Promise) {
  3. function returner() {
  4. return this.value;
  5. }
  6. function thrower() {
  7. throw this.reason;
  8. }
  9. Promise.prototype["return"] =
  10. Promise.prototype.thenReturn = function (value) {
  11. if (value instanceof Promise) value.suppressUnhandledRejections();
  12. return this._then(
  13. returner, undefined, undefined, {value: value}, undefined);
  14. };
  15. Promise.prototype["throw"] =
  16. Promise.prototype.thenThrow = function (reason) {
  17. return this._then(
  18. thrower, undefined, undefined, {reason: reason}, undefined);
  19. };
  20. Promise.prototype.catchThrow = function (reason) {
  21. if (arguments.length <= 1) {
  22. return this._then(
  23. undefined, thrower, undefined, {reason: reason}, undefined);
  24. } else {
  25. var _reason = arguments[1];
  26. var handler = function() {throw _reason;};
  27. return this.caught(reason, handler);
  28. }
  29. };
  30. Promise.prototype.catchReturn = function (value) {
  31. if (arguments.length <= 1) {
  32. if (value instanceof Promise) value.suppressUnhandledRejections();
  33. return this._then(
  34. undefined, returner, undefined, {value: value}, undefined);
  35. } else {
  36. var _value = arguments[1];
  37. if (_value instanceof Promise) _value.suppressUnhandledRejections();
  38. var handler = function() {return _value;};
  39. return this.caught(value, handler);
  40. }
  41. };
  42. };