firstValueFrom.js 952 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.firstValueFrom = void 0;
  4. var EmptyError_1 = require("./util/EmptyError");
  5. var Subscriber_1 = require("./Subscriber");
  6. function firstValueFrom(source, config) {
  7. var hasConfig = typeof config === 'object';
  8. return new Promise(function (resolve, reject) {
  9. var subscriber = new Subscriber_1.SafeSubscriber({
  10. next: function (value) {
  11. resolve(value);
  12. subscriber.unsubscribe();
  13. },
  14. error: reject,
  15. complete: function () {
  16. if (hasConfig) {
  17. resolve(config.defaultValue);
  18. }
  19. else {
  20. reject(new EmptyError_1.EmptyError());
  21. }
  22. },
  23. });
  24. source.subscribe(subscriber);
  25. });
  26. }
  27. exports.firstValueFrom = firstValueFrom;
  28. //# sourceMappingURL=firstValueFrom.js.map