of.js 690 B

12345678910111213141516171819202122
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.of = void 0;
  4. /**
  5. * Given a promise awaits it and returns a 3-tuple, with the following members:
  6. *
  7. * - First entry is either the resolved value of the promise or `undefined`.
  8. * - Second entry is either the error thrown by promise or `undefined`.
  9. * - Third entry is a boolean, truthy if promise was resolved and falsy if rejected.
  10. *
  11. * @param promise Promise to convert to 3-tuple.
  12. */
  13. const of = async (promise) => {
  14. try {
  15. return [await promise, undefined, true];
  16. }
  17. catch (error) {
  18. return [undefined, error, false];
  19. }
  20. };
  21. exports.of = of;
  22. //# sourceMappingURL=of.js.map