of.js 744 B

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